Skip to content

Instantly share code, notes, and snippets.

View pyk's full-sized avatar
🐈‍⬛
I may be slow to respond.

pyk pyk

🐈‍⬛
I may be slow to respond.
View GitHub Profile
@pyk
pyk / rnorrexp.c
Created August 23, 2016 14:55
The ziggurat method for RNOR and REXP https://www.jstatsoft.org/article/view/v005i08
/* The ziggurat method for RNOR and REXP
Combine the code below with the main program in which you want
normal or exponential variates. Then use of RNOR in any expression
will provide a standard normal variate with mean zero, variance 1,
while use of REXP in any expression will provide an exponential variate
with density exp(-x),x>0.
Before using RNOR or REXP in your main, insert a command such as
zigset(86947731 );
with your own choice of seed value>0, rather than 86947731.
(If you do not invoke zigset(...) you will get all zeros for RNOR and REXP.)
NEW_VERSION=206179d
OLD_VERSION=cd5726e
if [ ! -f "${NEW_VERSION}.tar.gz" ]; then
wget https://api.github.com/repos/facebookresearch/fasttext/tarball/${NEW_VERSION} -O ${NEW_VERSION}.tar.gz
else
echo "fastText: ${NEW_VERSION}.tar.gz exists"
fi
if [ ! -d "facebookresearch-fastText-${OLD_VERSION}" ]; then
@pyk
pyk / fix-clock-skew.sh
Last active August 9, 2016 16:27
Fix clock skew
# http://stackoverflow.com/questions/23281050/makefile-warning-warning-file-main-cpp-has-modification-time-2-1e04-s-in-th
# http://stackoverflow.com/questions/4210042/exclude-directory-from-find-command
find . -path ./.git -prune -o -type f -exec touch {} +
char buff[6] = {'h', 'e', 'l', 'l', 'o', '\0'};
/* or */
char *buff = "hello"; /* \0 implicitly appended */
/* or */
char buff[] = "hello";
@pyk
pyk / note.sh
Created June 18, 2016 19:12
new way to install llvm libc++ in Ubuntu 14.04 Trusty
# http://llvm.org/apt/
sudo bash -c "cat >> /etc/apt/sources.list" << LLVMAPT
# LLVM
deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty main
deb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty main
# 3.5
deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.5 main
deb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.5 main
# 3.6
@pyk
pyk / roulette.java
Last active October 22, 2017 08:27
Roulette-wheel selection via stochastic acceptance. More on http://arxiv.org/abs/1109.3627 https://en.wikipedia.org/wiki/Fitness_proportionate_selection
public class roulette {
public static void main(String [] args) {
int n=4;
double [] weight = new double [n];
weight[0]=0.4;
weight[1]=0.3;
weight[2]=1.2;
weight[3]=0.1;
double max_weight=1.2;
int [] counter = new int[n];
@pyk
pyk / README.md
Last active September 18, 2019 17:53
Install Oracle java 8 on debian jessie

Run

wget https://gist.githubusercontent.com/pyk/19a619b0763d6de06786/raw/b09ce3a6626484adb5339597dfd391d0db9fe3cb/install-oracle-java-8-on-debian-jessie.sh
sh install-oracle-java-8-on-debian-jessie.sh

See the following blog post

@pyk
pyk / echoserver.go
Created January 21, 2016 03:16
echoserver - A simple TCP echo server written in Go
// echoserver - A simple TCP echo server written in Go
//
// Build:
// % go build echoserver.go
//
// Usage:
// % ./echoserver 8080
//
// License:
// BSD 3-clause Revised
/* Alternative version of https://github.com/antirez/redis/blob/3.2/src/server.c#L3651-L3666 */
void usage(void) {
fprintf(stderr,
"Usage: ./redis-server [/path/to/redis.conf] [options]\n"
" ./redis-server - (read config from stdin)\n"
" ./redis-server -v or --version\n"
" ./redis-server -h or --help\n"
" ./redis-server --test-memory <megabytes>\n\n"
"Examples:\n"
" ./redis-server (run the server with default conf)\n"
@pyk
pyk / .indent.pro
Last active December 15, 2015 11:07
This is a list of options that will be used by indent(1) to formatting the C source code.
/* indent(1) Profile
* This is a list of options that will be used by indent(1) to formatting the
* C source code.
*
* For complete available options
* https://www.gnu.org/software/indent/manual/html_section/indent_15.html#SEC17
*
* Copyright 2015 Bayu Aldi Yansyah <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");