Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
''' create an .epub file from a given directory '''
import os, sys, zipfile
import Tkinter, tkFileDialog
def zipdir(zipf, path):
''' add everything under path under zipf '''
for root, dirs, files in os.walk(path):
@3ki5tj
3ki5tj / randperm.c
Created August 6, 2016 00:22
Random permutation
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* generate a random permutation of array `a` in place */
static void randperm(int n, double *a)
{
int i, j;
double x;
@3ki5tj
3ki5tj / MerryChrismas.c
Created December 24, 2015 03:22
Print Merry Christmas!
double _[]={42060394849482.6,6.289356622075972e33,600};main(){(*_*=2,_[1]/=2,--_[2])?main():puts((char*)_);}
@3ki5tj
3ki5tj / getpdfnums.py
Created May 28, 2015 18:32
get numbers copy and pasted from PDF
#!/usr/bin/env python
''' get numbers from text pasted from PDF file '''
from math import *
@3ki5tj
3ki5tj / bits.h
Created December 8, 2014 21:11
bitwise operations
/*
http://graphics.stanford.edu/~seander/bithacks.html
*/
int is_power_of_two(unsigned int x)
{
return ((x != 0) && !(x & (x - 1)));
}
int count_bits(unsigned int v)
@3ki5tj
3ki5tj / pdbwrap.py
Created December 5, 2014 19:50
Wrap coordinates to make atoms in a cluster stay together
#!/usr/bin/env python
''' wrapping coordinates '''
import os, sys
from math import *
@3ki5tj
3ki5tj / fit1overr.py
Created December 5, 2014 19:42
Fit a charge-charge interaction tail
#!/usr/bin/env python
''' fit a simple equation '''
import os, sys
from math import *
@3ki5tj
3ki5tj / random_color.js
Last active August 29, 2015 14:10
Random color
function random_color(cmin, cmax)
{
var x = Math.random() * 6;
var i = Math.floor( x ), r = 0, g = 0, b = 0;
if ( cmin == undefined || cmin == null ) cmin = 0;
if ( cmax == undefined || cmax == null ) cmax = 255;
var cvar = cmax - cmin + 1;
x -= i;
if ( i < 1 ) { // red to yellow
@3ki5tj
3ki5tj / kiss.c
Last active August 29, 2015 14:10
KISS random number generator
#include <stdio.h>
#include <math.h>
__inline double rand01_kiss(void)
{
#define znew(z) (z = 36969 * (z & 65535) + (z >> 16))
#define wnew(w) (w = 18000 * (w & 65535) + (w >> 16))
#define MWC(z, w) ((znew(z) << 16) + wnew(w))
@3ki5tj
3ki5tj / ocp.c
Created November 18, 2014 23:47
Solving the integral equation for the one-component plasma
/* Solving the integral equation for the one-component plasma
* To compile
* gcc ocp.c -lfftw3 -lm
* To run the program
* ./a.out
* To view the output
* gnuplot "cr.dat" u 1:2 t "c(r)", "" u 1:3 t "t(r)", "" u 1:($2+$3) t "h(r)"
**/
#include <stdio.h>
#include <stdlib.h>