Skip to content

Instantly share code, notes, and snippets.

Option("bad") filter { _ != None } map { catching(classOf[NumberFormatException]) opt _.toInt } getOrElse None
@kai5263499
kai5263499 / gist:7d0920e869f5657ea101
Created July 11, 2014 01:05
Javascript replace on a capture group
story = story.replace(person\.go\?ID=\d+"\s*[^>]*>([^(<)]+)<\/a>/g,function() {
return 'person.go?ID='+escape(arguments[1].replace(/\./g,''))+'">'+arguments[1]+'';
});
@kai5263499
kai5263499 / gist:766b4cbf9f2e621ecfa4
Created July 11, 2014 01:30
produce a list of tuples which describes the chunks adjusted to the nearest newline
getChunkDivisions(File, 0, Chunksize, ChunkDivisions) ->
[{chunk,0,Chunksize}|ChunkDivisions];
getChunkDivisions(File, Size, Chunksize, ChunkDivisions) ->
if
Size-Chunksize=<0 ->
ComputedChunkEnd = Chunksize-(Chunksize-Size),
CorrectedChunkEnd = walkToNextLineBreak(File, ComputedChunkEnd),
getChunkDivisions(File, 0, CorrectedChunkEnd, ChunkDivisions);
true ->
ComputedChunkEnd = Size-Chunksize,
@kai5263499
kai5263499 / downloadqueue.sh
Created September 6, 2014 04:58
This script reads the first entry from a text file and downloads it. Includes locking to ensure only one download is run at a time. After the download is complete, the first entry in the text file is removed, effectively creating a queue in bash of sorts.
#!/bin/bash
cd ~
LOCKFILE="download-running"
if [ -f $LOCKFILE ];then
exit 0
fi
touch $LOCKFILE
@kai5263499
kai5263499 / proxy.ashx
Created September 6, 2014 05:03
A simple proxy in C# which persists the entire request to the target
<%@ WebHandler Language="C#" CodeBehind="proxy.ashx.cs" Class="PIPE.Host.proxy" %>
@kai5263499
kai5263499 / keybase.md
Created September 26, 2014 01:45
Keybase verification

Keybase proof

I hereby claim:

  • I am kai5263499 on github.
  • I am kai5263499 (https://keybase.io/kai5263499) on keybase.
  • I have a public key whose fingerprint is 49F9 E276 89A6 D0EE 5935 6B9B EE8B 7537 16A0 D1D5

To claim this, I am signing this object:

@kai5263499
kai5263499 / gist:061159ecf7f716fa4b63
Created October 19, 2014 15:49
Simple linked list implementation in Python
# From http://interactivepython.org/LpOMZ/courselib/static/pythonds/BasicDS/linkedlists.html
class Node:
def __init__(self,initdata):
self.data = initdata
self.next = None
class LinkedList:
def __init__( self ):
self.head = None
self.tail = None
@kai5263499
kai5263499 / random_array.py
Last active October 24, 2017 18:37
generate a random array
from random import randrange
from random import randint
def intArray(maxrand=100,randomValues=False):
l=randrange(maxrand)
o=[]
for i in range(1,l):
if(randomValues):
o.append(randrange(maxrand))
// Permute the string using Heap's algorithm https://en.wikipedia.org/wiki/Heap%27s_algorithm
var perm = function(list, n){
if(n==1){
var inputString = list.join('');
console.log(inputString);
} else {
for(var c=0;c<n;c++){
perm(list,n-1);
if(n%2===0){
var temp1=list[c];
@kai5263499
kai5263499 / SelectNextLimit.js
Created January 14, 2015 16:29
This class generates an upper and lower bound of a hex string (ie md5 or sha1 hash)
var SelectNextLimit = function(upper,res) {
var base = parseInt(upper,16);
var resolution = parseInt(res, 16);
var upper,lower;
this.next = function() {
upper = (base).toString(16);