Skip to content

Instantly share code, notes, and snippets.

making my way downtown, walking fast

vgmoose vgmoose

making my way downtown, walking fast
View GitHub Profile
vgmoose / gist:71b99ebec86c6558f041
Created Jan 9, 2015
Move all 0s to the front in an array of 1s and 0s
View gist:71b99ebec86c6558f041
def solve(a):
lastNonZeroPos = -1
for x in range(0, len(a)):
# if the lastnonzeropos isn't set, and this is nonzero
if lastNonZeroPos < 0 and a[x] != 0:
# set the last non zero pos
lastNonZeroPos = x
vgmoose / gist:6ae367cd08fd4534553b
Created Jan 9, 2015
dynamic programming solution to fibonacci sequence
View gist:6ae367cd08fd4534553b
public class fib
public static void main(String[] args)
public static int fib(int x)
// create an array of size x
import random, sys
dirs = ["up", "down"]
class Particle:
def __init__(self, seed, spin):
self.seed = seed
self.spin = spin
def measure(self, angle):
# return up or down
View gist:3f880418b1879dbcc447
import sys
a = open(sys.argv[1]).read()
for x in range(0, len(a), 16):
line = a[x:x+16]
hexl = ' '.join(y.encode('hex') for y in line)
hexl += ' '*(47-len(hexl))
hexl = hexl[:24] + " " + hexl[24:]
line = line.replace("\n", ".")
import os
keys = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16]
term = 0x19
def decrypt(data):
output = ""
nextwrite = False
bytesofar = 0
import urllib, subprocess, os
# fetches latest youtube video from specified channel and casts to chromecast
# needs to be run as root to scan the network for the mac address
# requires: castnow and arp-scan installed
author = "rhettandlink2" # youtube channel
mac = "UR:MA:CA:DD:RE:SS" # chromecast mac address
iface = "wlan0" # interface to LAN
vgmoose /
Created Jun 17, 2015
Like python -m SimpleHTTPServer, but encrypted!
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('', 9000), SimpleHTTPServer.SimpleHTTPRequestHandler)
# generate server.pem with:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='../server.pem', server_side=True)
import random, hashlib, sys
from collections import defaultdict
import matplotlib.pyplot as plt
matlab = True
print("you will need to install to display the graph")
matlab = False
if [ "$#" -ne 1 ]
echo "Usage: ramdisk size_in_MB"
exit 1
if [[ $OSTYPE == *"linux"* ]]
vgmoose /
Last active Aug 29, 2015
List top 20 files + sizes over 300MB in / or specified directory
import os
import functools
import sys
from heapq import *
from math import log
def pretty_size(n,pow=0,b=1024,u='B',pre=['']+[p for p in'KMGTPEZY']):
return "%%.%if %%s%%s"%abs(pow%(-pow-1))%(n/b**float(pow),pre[pow],u)