Skip to content

Instantly share code, notes, and snippets.

Avatar
🌱
making my way downtown, walking fast

vgmoose vgmoose

🌱
making my way downtown, walking fast
View GitHub Profile
@vgmoose
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
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)
{
System.out.println(fib(5));
}
public static int fib(int x)
{
// create an array of size x
View seeds.py
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", ".")
View data.py
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
View latestcast.py
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
vgmoose / SimpleHTTPSServer.py
Created Jun 17, 2015
Like python -m SimpleHTTPServer, but encrypted!
View SimpleHTTPSServer.py
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('0.0.0.0', 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)
httpd.serve_forever()
View crypto.py
import random, hashlib, sys
from collections import defaultdict
try:
import matplotlib.pyplot as plt
matlab = True
except:
print("you will need to install http://matplotlib.org/users/installing.html to display the graph")
matlab = False
View ramdisk.sh
#!/bin/bash
if [ "$#" -ne 1 ]
then
echo "Usage: ramdisk size_in_MB"
exit 1
fi
if [[ $OSTYPE == *"linux"* ]]
then
@vgmoose
vgmoose / list.py
Last active Aug 29, 2015
List top 20 files + sizes over 300MB in / or specified directory
View list.py
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']):
pow,n=min(int(log(max(n*b**pow,1),b)),len(pre)-1),n*b**pow
return "%%.%if %%s%%s"%abs(pow%(-pow-1))%(n/b**float(pow),pre[pow],u)