Skip to content

Instantly share code, notes, and snippets.

@nishidy
nishidy / random_memoranda.md
Last active October 13, 2017 14:04
Random memoranda

vmstat

$ vmstat -n 2 | perl -e 'while(<>){print localtime().": $_"}'
Fri Dec 30 15:34:51 2016: procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
Fri Dec 30 15:34:51 2016:  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
Fri Dec 30 15:34:51 2016:  2  0  57216  94916  93012 135552    4   22   601    39  216  593  2  2 94  2
Fri Dec 30 15:34:53 2016:  0  0  57216  94296  93012 135552    0    0     0     0  201  737  1  1 98  0
Fri Dec 30 15:34:55 2016:  0  0  57216  94296  93012 135552    0    0     0     0  176  707  1  1 98  0
Fri Dec 30 15:34:57 2016:  0  0  57216  94296  93012 135552    0    0     0     0  174  656  1  1 98  0
@nishidy
nishidy / hash.cpp
Last active January 18, 2017 15:17
My own hash implementation in C++11
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <unordered_map>
#include <sstream>
#include <time.h>
#include <sys/time.h>
#include <openssl/md5.h>
#include <openssl/sha.h>
@nishidy
nishidy / heap_sort.c
Last active December 15, 2016 06:39
Heap sort in C
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
typedef int TYPE;
typedef unsigned int UINT;
double print_time(struct timeval *s, struct timeval *e){
@nishidy
nishidy / in_place_quick_sort.go
Created December 11, 2016 22:29
In place Quick Sort in go
package main
import (
"fmt"
"math/rand"
"os"
"sort"
"strconv"
"time"
)
@nishidy
nishidy / sort.cpp
Last active December 10, 2016 15:39
Reference code of sort in C++
#include <iostream>
#include <vector>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
using namespace std;
typedef int TYPE;
@nishidy
nishidy / in_place_quick_sort.c
Last active December 11, 2016 13:30
In-place Quick Sort in C
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
typedef double TYPE;
typedef unsigned int UINT;
int cmp(const void*a, const void*b){
@nishidy
nishidy / max_sub_array.c
Last active December 16, 2016 16:54
Find maximum sum of sub array in O(N^3), O(N^2), O(NlogN), O(N).
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
//typedef int TYPE;
typedef long TYPE;
double print_time(struct timeval *s, struct timeval *e){
int si = (s->tv_sec%1000000)*1000+s->tv_usec/1000;
@nishidy
nishidy / find_a_lost_number.c
Last active November 29, 2016 15:26
Find a lost number in O(N) better than O(NlogN) by sort.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
double print_time(struct timeval *s, struct timeval *e){
int si = (s->tv_sec%1000000)*1000+s->tv_usec/1000;
int ei = (e->tv_sec%1000000)*1000+e->tv_usec/1000;
return (double)(ei-si)/1000.0;
}
@nishidy
nishidy / thread_merge_sort.c
Last active December 10, 2016 08:40
Merge sort with multi-threaded (without lock)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <pthread.h>
#include <errno.h>
unsigned long mem_size;
unsigned int malloc_cnt;
@nishidy
nishidy / in_place_merge_sort.c
Last active December 16, 2016 16:36
In-place merge sort
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
void print(int* a, int n){
int i=0;
printf("[");
for(i=0;i<n;i++){