View gist:71b99ebec86c6558f041
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View gist:6ae367cd08fd4534553b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View SimpleHTTPSServer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -ne 1 ] | |
then | |
echo "Usage: ramdisk size_in_MB" | |
exit 1 | |
fi | |
if [[ $OSTYPE == *"linux"* ]] | |
then |
View list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |