Skip to content

Instantly share code, notes, and snippets.

@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;
// 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
J=1;exec'''z="";b=-1.6;
exec'x=y=0;exec"x,y=2*x
*y+J,y*y-x*x+b;"*20;z+=
" O"[x*x+y*y<2];b+=.04;
'*60;print z;J-=.1;'''.
replace('\n','')*20#Jay
#define _+o[$&1][O
o[2][1024],$;main(
O){for(;getchar(),
puts("\e[2J");$++)
for(O=32;O++<992;)
O&31&&printf(~O&31
?(o[~$&1][O]=$?(_-
33]_-32]_-31]_-1]_
+1]_+31]_+32]_+33]
|_])==3:rand()&1)?