Skip to content

Instantly share code, notes, and snippets.

View vgmoose's full-sized avatar
🌱
making my way downtown, walking fast

vgmoose vgmoose

🌱
making my way downtown, walking fast
View GitHub Profile
@vgmoose
vgmoose / gist:71b99ebec86c6558f041
Created January 9, 2015 02:35
Move all 0s to the front in an array of 1s and 0s
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 January 9, 2015 03:04
dynamic programming solution to fibonacci sequence
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
@vgmoose
vgmoose / seeds.py
Created January 18, 2015 16:08
seeds
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
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", ".")
@vgmoose
vgmoose / data.py
Last active August 29, 2015 14:14
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
vgmoose / SimpleHTTPSServer.py
Created June 17, 2015 02:04
Like python -m SimpleHTTPServer, but encrypted!
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()
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
#!/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 August 29, 2015 14:25
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']):
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)