- 1
https://www.reddit.com/r/ProgrammerHumor/comments/4to9vx/so_im_working_on_a_new_language/
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+4
https://www.reddit.com/r/ProgrammerHumor/comments/4to9vx/so_im_working_on_a_new_language/
"So I'm working on a new language…"
+7
#include <iostream>
struct Test {
operator auto() -> bool { return true; }
};
int main() {
std::cout << std::boolalpha << Test() << std::endl;
}
operator auto() завезли!
http://ideone.com/sGxeQn
−3
function formSelect($itxt, $name = '', $val = array(), $selected = 0, $data = 0, $nullF = false, $atr = '', $optatr = array()) {
if(is_array($selected)) { $atr .= ' multiple'; }
$html = '<select name="'.$name.'" '.$atr.">\r\n";
if($nullF) {
$t = ($nullF === true) ? ' ' : $nullF;
$html .= '<option value="0">'.$t.'</option>'; }
if($data == 3) { $start = $itxt; $count = $val[0]; $step = $val[1]; }
else { $count = count($itxt); }
for($i = 0; $i < $count; $i++) {
// 4 - для быза данных
switch($data) {
case 1: $key = $val[$i]; $txt = $itxt[$i]; break;
case 2: $key = $i; $txt = $itxt[$i]; break;
case 3: $txt = $key = ($start + ($step*$i)); break;
case 4: $key = $itxt[$i][$val[0]]; $txt = $itxt[$i][$val[1]]; break;
default: $key = $txt = $itxt[$i]; break;
}
$sel = '';
if(is_array($selected)) {
if(in_array($key, $selected)) { $sel = 'selected'; }
} elseif($selected == $key) { $sel = 'selected'; }
if(!empty($optatr[$i])) { $opt = $optatr[$i]; } else { $opt = ''; }
$html .= '<option value="'.$key.'" '.$sel.$opt.'>'.$txt."</option>\r\n";
}
$html .= "</select>\r\n";
return $html;
}
Теперь бызить вореции как никогда просто!
+3
#define __DEBUG
#ifdef __DEBUG
#define print_pair(p) do{std::cout << "(" << ((p).first + 1) << ", "\
<< ((p).second + 1) << ")" << std::endl;}while(0);
#endif
Graph::result
Graph::dijkstra (int start)
{
#ifdef __DEBUG
std::cout << "Dijkstra algorithm tracing:" << std::endl;
#endif
distances[start] = 0;
std::set<std::pair<int, int>> q;
q.insert (std::make_pair(distances[start], start));
while (!q.empty())
{
#ifdef __DEBUG
std::cout << "top element of a set: ";
print_pair(*q.begin());
#endif
int current = q.begin()->second;
q.erase(q.begin());
for (int i = 0; i < adj[current].size(); ++i)
{
#ifdef __DEBUG
std::cout << "current vertex: " << (current + 1);
std::cout << " ad current state of distances array is: " << std::endl;
for (auto i: distances)
std::cout << i << " ";
std::cout << std::endl;
#endif
int to = adj[current][i].second;
int length = adj[current][i].first;
// Relaxations
if (distances[to] > distances[current] + length)
{
#ifdef __DEBUG
std::cout << "relaxation for edge (" << current << ", " << to << ") ";
std::cout << "with weight " << length << std::endl;
#endif
q.erase(std::make_pair(distances[to], to));
distances[to] = distances[current] + length;
path[to] = current;
q.insert(std::make_pair(distances[to], to));
}
}
}
// Replace INF by -1
std::replace (distances.begin(), distances.end(), INF, -1);
return distances;
}
Я у мамы решил подебажить как мыщъх дебажил при помощи отладочной печати. Вот что получилось.
+11
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication23 {
class InternalRandom {
static double x;
Task t, t2;
public InternalRandom() {
t = new Task(ThreadFunc);
t.Start();
t2 = new Task(ThreadFunc);
t2.Start();
}
public double Next() {
return x;
}
public double Next(double max) {
x+=7;
return NORMALNYYREM(x,max);
//return Math.IEEERemainder(max, x);
}
static double NORMALNYYREM(double A,double B) {
return A - ((double)((long)(A/B))) * B;
}
static void ThreadFunc() {
while(true) {
x += 1;
}
}
}
class Program {
static InternalRandom ir;
static void Main(string[] args) {
ir = new InternalRandom();
for(int i = 1; i <= 20; i++) {
Console.WriteLine( "#"+i+" = "+ Random() );
}
Console.ReadLine();
//Environment.Exit(0);
}
static double Random() {
return ir.Next(10);
}
}
}
+2
#define CREATE_EVENT_LISTENER(_elname, arg1_type, arg1_name) \
class _elname : public EventListener \
{ \
private: \
class IContainer \
{ \
public: \
virtual void Call(arg1_type arg1_name) = 0; \
virtual ~IContainer() {} \
}; \
\
class FunctionContainer : public IContainer \
{ \
private: \
typedef void(*__CallbackPtr)(arg1_type); \
public: \
FunctionContainer(__CallbackPtr fn) \
{ \
this->fn = fn; \
} \
\
virtual void Call(arg1_type arg1_name) \
{ \
fn(arg1_name); \
} \
\
private: \
__CallbackPtr fn; \
}; \
\
template<class T, class Q> \
class MethodContainer : public IContainer \
{ \
public: \
MethodContainer(T method, Q _this) \
{ \
this->method = method; \
this->_this = _this; \
} \
\
virtual void Call(arg1_type arg1_name ) \
{ \
(_this->*method)(arg1_name); \
} \
\
private: \
T method; \
Q _this; \
}; \
public: \
typedef void(*__FN_CALLBACK)(arg1_type); \
\
_elname(__FN_CALLBACK fn) \
{ \
this->container = new FunctionContainer(fn); \
} \
\
template <class T, class Q> \
_elname(T method, Q _this) \
{ \
this->container = new MethodContainer<T, Q>(method, _this); \
} \
\
void Call(arg1_type arg1_name) \
{ \
container->Call(arg1_name); \
} \
\
virtual ~_elname() \
{ \
delete this->container; \
} \
private: \
IContainer* container; \
}; \
#define CREATE_EVENT(_ename, _elname, arg1_type, arg1_name) \
class _ename : public Event \
{ \
public: \
void AddListener(_elname* listener) \
{ \
Event::AddListener(listener); \
} \
\
void Handle(arg1_type arg1_name) \
{ \
for (size_t i = 0; i < this->listeners.size(); i++) \
{ \
((_elname*)listeners[i])->Call(arg1_name); \
} \
} \
\
void RemoveListener(_elname* listener) \
{ \
Event::RemoveListener(listener); \
} \
\
}; \
Я когда то это написал. Думал, это хорошая идея...
Полный файл: https://github.com/arhyme/CPP_EVENTS/blob/master/Event.h
+7
public static List<String> ParseVKPermissionsFromInteger(int permissionsValue)
{
var res = new List<String>();
if ((permissionsValue & 1) > 0) res.Add(NOTIFY);
if ((permissionsValue & 2) > 0) res.Add(FRIENDS);
if ((permissionsValue & 4) > 0) res.Add(PHOTOS);
if ((permissionsValue & 8) > 0) res.Add(AUDIO);
if ((permissionsValue & 16) > 0) res.Add(VIDEO);
if ((permissionsValue & 128) > 0) res.Add(PAGES);
if ((permissionsValue & 1024) > 0) res.Add(STATUS);
if ((permissionsValue & 2048) > 0) res.Add(NOTES);
if ((permissionsValue & 4096) > 0) res.Add(MESSAGES);
if ((permissionsValue & 8192) > 0) res.Add(WALL);
if ((permissionsValue & 32768) > 0) res.Add(ADS);
if ((permissionsValue & 65536) > 0) res.Add(OFFLINE);
if ((permissionsValue & 131072) > 0) res.Add(DOCS);
if ((permissionsValue & 262144) > 0) res.Add(GROUPS);
if ((permissionsValue & 524288) > 0) res.Add(NOTIFICATIONS);
if ((permissionsValue & 1048576) > 0) res.Add(STATS);
return res;
}
Больше кала тут: github.com/VKCOM/vk-windowsphone-sdk
+2
https://www.youtube.com/watch?v=Zrd7kFFCfp4
https://www.youtube.com/watch?v=yuMlhKI-pzE
CPU
0
function syn_s_lms_support_get_bl_specific_urls($bl_node) {
$bl_specific_urls=array();
$url = field_extract_value('node', $bl_node, 'field_business_website', 'url');
if (isset($url[0]) && strlen($url[0]) ) {
$bl_specific_urls[] = $url[0];
}
$url = field_extract_value('node', $bl_node, 'field_business_yelp', 'url');
if (isset($url[0]) && strlen($url[0]) ) {
$bl_specific_urls[] = $url[0];
}
$url = field_extract_value('node', $bl_node, 'field_business_gplus', 'url');
if (isset($url[0]) && strlen($url[0]) ) {
$bl_specific_urls[] = $url[0];
}
$url = field_extract_value('node', $bl_node, 'field_business_facebook', 'url');
if (isset($url[0]) && strlen($url[0]) ) {
$bl_specific_urls[] = $url[0];
}
$twitname = field_extract_value('node', $bl_node, 'field_business_twitter');
if ($twitname) {
$twit_name_clean = str_replace("@", '', $twitname);
$bl_specific_urls[] = 'https://twitter.com/' . $twit_name_clean;
}
return $bl_specific_urls;
}
Давай, ман не читай,
код пиши от души.
+1
$arResult["ORDER_ID"] = (int)CSaleOrder::DoSaveOrder($arOrderDat, $arFields, 0, $arResult["ERROR"]);
if ($arResult["ORDER_ID"] > 0 && empty($arResult["ERROR"]))
{
CSaleBasket::OrderBasket($arResult["ORDER_ID"], CSaleBasket::GetBasketUserID(), SITE_ID, false);
}
Нам насрать на то что DoSaveOrder уже внутри себя делает OrderBasket, мы сделаем это еще раз.