Skip to content

Instantly share code, notes, and snippets.

@adnils
adnils / af-magic.zsh-theme
Created December 10, 2013 08:24
fix virtualenv
# af-magic.zsh-theme
#
# Author: Andy Fleming
# URL: http://andyfleming.com/
# Repo: https://github.com/andyfleming/oh-my-zsh
# Direct Link: https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme
#
# Created on: June 19, 2012
# Last modified on: June 20, 2012
@adnils
adnils / murmur.js
Created January 30, 2014 10:03
murmur hash
function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);
@adnils
adnils / doublefloat.js
Created January 30, 2014 10:05
find the next representable double float
"use strict";
var SMALLEST_NORMALIZED_VALUE = 2.2250738585072014e-308; // Math.pow(2, -1022)
var MIN_VALUE = 5e-324 === 0 ? SMALLEST_NORMALIZED_VALUE : 5e-324;
var MAX_VALUE = Number.MAX_VALUE;
Math.nextUp = function (x) {
x = Number(x);
if (x !== x) {
return x;
/*
d3.phylogram.js
Wrapper around a d3-based phylogram (tree where branch lengths are scaled)
Also includes a radial dendrogram visualization (branch lengths not scaled)
along with some helper methods for building angled-branch trees.
Copyright (c) 2013, Ken-ichi Ueda
All rights reserved.
// Given a number, find the next higher number which has the exact same set of digits as the original number
// http://stackoverflow.com/questions/9368205/given-a-number-find-the-next-higher-number-which-has-the-exact-same-set-of-digi
function nextUp(iNumber){
var sDigitsSorted = iNumber.toString().split('').sort().join('');
var aPermutations = (function(){
var i = parseInt(iNumber.toString().split('').sort().reverse().join(''),10) + 1,
a = [];
@adnils
adnils / README.md
Created February 16, 2014 16:33 — forked from nicerobot/README.md
Node .pkg uninstaller

To run this, you can try:

curl -ks https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh | bash

I haven't tested this script doing it this way but i run a lot of my Gists like this so maybe this one'll work too.

Alternatively,

curl -ksO https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh

chmod +x ./uninstall-node.sh

@adnils
adnils / gist:9365973
Created March 5, 2014 12:07
lol snapchat
require 'openssl'
ARGV.each do|a, index|
data = File.open(a, 'r:ASCII-8BIT').read
c = OpenSSL::Cipher.new('AES-128-ECB')
c.decrypt
c.key = 'M02cnQ51Ji97vwT4'
o = ''.force_encoding('ASCII-8BIT')
data.bytes.each_slice(16) { |s| o += c.update(s.map(&:chr).join) }
o += c.final
@adnils
adnils / bootychaser.pl
Last active August 29, 2015 13:57
dynamic tail -F that watches for new files
#!/usr/bin/perl
use strict;
use Time::HiRes qw (usleep);
use IO::Select;
my $patterns = (join ' ', @ARGV or "*");
my $sel = IO::Select->new;
my (%files, $last);
for (my $nop=0;;$nop=1)
M[16],X=16,W,k;main(){T(system("stty cbreak")
);puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i
,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M
[w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<<
(l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k)
]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d
-1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X]
*i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4;
)s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4||
puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2
@adnils
adnils / gist:9993846
Created April 5, 2014 16:11
2048 in C
// Original file by Jay Chan:
// https://gist.github.com/justecorruptio/9967738
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#define GRID_LEN 16