- 1
http://www.businessinsider.com/the-russian-internet-thinks-putin-is-dead-2015-3
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 223
+120
http://www.businessinsider.com/the-russian-internet-thinks-putin-is-dead-2015-3
политота
+51
template<class T, size_t N>
constexpr size_t sa(T (&)[N])
{
return N;
};
static std::memory_order mmo[] =
{
memory_order_relaxed,
memory_order_consume,
memory_order_acquire,
memory_order_release,
memory_order_acq_rel,
memory_order_seq_cst
};
std::memory_order current_program_memory_order()
{
return mmo[rand()%sa(mmo)];
}
void current_program_memory_barier()
{
std::atomic_thread_fence(current_program_memory_order());
}
+54
class SpinLock
{
std::atomic_flag lck;
public:
SpinLock(){
unlock();
}
__forceinline void lock(){
while (lck.test_and_set(std::memory_order_acquire)){
}
}
__forceinline void unlock(){
lck.clear(std::memory_order_release);
}
};
+49
#include <iostream>
int get_number() {
return 5;
}
int magic_number(int foo()) {
return foo();
}
int main(void)
{
std::cout << magic_number(get_number) << std::endl;
}
http://ideone.com/TbV0jD
−142
merge tablename as target
using (values ('new value', 'different value'))
as source (field1, field2)
on target.idfield = 7
when matched then
update
set field1 = source.field1,
field2 = source.field2,
...
when not matched then
insert ( idfield, field1, field2, ... )
values ( 7, source.field1, source.field2, ... )
+136
#include <stdint.h>
#include <Windows.h>
#include <intrin.h>
typedef long dt;
namespace {
dt InitializationIsInProgress = 0;
dt InitializationIsFinished = 0;
}
dt InterlockedLoad(dt volatile * t){
return InterlockedCompareExchange(t, 0, 0);
}
dt InterlockedAssign(dt volatile * t, dt v){
dt c = 0;
while (c = InterlockedCompareExchange(t, v, c));
}
void InitializeSystem(){
if (InterlockedLoad(&InitializationIsFinished) == 1)
return;
while (InterlockedCompareExchange(&InitializationIsInProgress, 1, 0) == 1) Sleep(0);
//__ReadWriteBarrier();
if (InterlockedLoad(&InitializationIsFinished) == 1)
return;
Work();
InterlockedAssign(&InitializationIsFinished, 1);
InterlockedAssign(&InitializationIsInProgress, 0);
}
Не судите строга. Воспользуюсь как пастебином. Если найдете ошибки - пришлю пирожок.
+130
Я не жду чтобы меня плюсовали, но давайте сделаем небольшую игру, ломающую стереотипы?
Например рогалик в небольшое кол-во строк. В качестве главного героя можно взять крутого парня ломающего черепа.
+141
strcat(strcpy(malloc(strlen(argv[0]) + sizeof(".track")), argv[0]), ".track")
+54
// We now have a locale string, but the global locale can be changed by
// another thread. If we allow this thread's locale to be updated before we're done
// with this string, it might be freed from under us.
// Call versions of the wide-to-MB-char conversions that do not update the current thread's
// locale.
//...
/*
* Note that we are using a risky trick here. We are adding this
* locale to an existing threadlocinfo struct, and thus starting
* the locale's refcount with the same value as the whole struct.
* That means all code which modifies both threadlocinfo::refcount
* and threadlocinfo::lc_category[]::refcount in structs that are
* potentially shared across threads must make those modifications
* under _SETLOCALE_LOCK. Otherwise, there's a race condition
* for some other thread modifying threadlocinfo::refcount after
* we load it but before we store it to refcount.
*/
MS VS 2013 CRT
+95
double[,] ThreadMatrixMult(int size, double[,] m1, double[,] m2)
{
double[,] result = new double[size, size];
var threads = new List<Thread>(size);
for (int i = 0; i < size; i++)
{
var t = new Thread( ti =>
{
int ii = (int)ti;
for (int j = 0; j < size; j++)
{
result[ii, j] = 0;
for (int k = 0; k < size; k++)
{
result[ii, j] += m1[ii, k] * m2[k, j];
}
}
});
threads.Add(t);
t.Start(i);
}
foreach (Thread thread in threads)
thread.Join();
return result;
}