Skip to content

Instantly share code, notes, and snippets.

@snoopspy
snoopspy / test
Last active August 29, 2015 14:22
#include <cstring>
#include <iostream>
char buf[256];
size_t idx = 0;
void *malloc(size_t size) {
void* res = &buf[idx];
memset(res, 0xFF, size);
idx += size;
@snoopspy
snoopspy / Makefile
Last active August 29, 2015 14:19
global_object_glog_test
all:
g++ -o main.o -c main.cpp
g++ -o global_object_glog_test main.o -lglog -pthread
clean:
rm -rf global_object_glog_test
rm -rf *.o
#include <algorithm>
#include <iostream>
using namespace std;
struct Num {
int n[9];
int cnt;
Num() {
for (int i = 0; i < 9; i++)
#include <iostream>
int reverse_digit(int n) {
int res = 0;
while (n != 0) {
res = res * 10 + (n % 10);
n /= 10;
}
return res;
}
#include <algorithm>
#include <thread>
#include <glog/logging.h>
using namespace std;
volatile uint64_t g_value;
void write_proc() {
constexpr int CNT = 1000000;
#include <iostream>
int main()
{
{
// float to int
float f = 1;
int i = *((int*)&f);
std::cout << i << std::endl;
}
@snoopspy
snoopspy / gist:bdc331b5c56d251991d7
Last active August 29, 2015 14:17
How to get third largest number in array
#include <assert.h> // for assert
#include <iostream> // for std::cout
#include <climits> // for INT_MAX
int get_third_largest_number(int* arr, int n)
{
int max1 = -INT_MAX;
int max2;
int max3;
#include <iostream>
unsigned __attribute__ ((noinline)) f(unsigned a)
{
return a/9;
.cfi_startproc
movl %edi, %eax
movl $954437177, %edx
mull %edx
shrl %edx
#include <map>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <VPerformanceElapsedTimer>
struct Key1
{
int a;
int b;
SOURCES = main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = $(shell basename $(PWD))
LDFLAGS += -lpthread
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CXX) -o $@ $(OBJECTS) $(LDFLAGS)