Skip to content

Instantly share code, notes, and snippets.

View beefy's full-sized avatar
✌️

Nate Schultz beefy

✌️
  • Zendesk
  • Philadelphia, PA
  • 07:21 (UTC -04:00)
View GitHub Profile
@beefy
beefy / instagram_dentist_bot.py
Last active May 4, 2016 18:29
A web crawler/scrapper for the Instagram API, never perfected/finished
__author__ = 'Nathaniel'
import requests
import mysql.connector
import time
import unicodedata
# region sql stuff
def sql_filter_param(text):
output = unicodedata.normalize('NFKD', text).encode('ascii','ignore');
@beefy
beefy / NetworkTask.java
Last active April 15, 2016 02:33
encoding Unicode (including emojis) for web server
String[] msg_chars = new String[msg_text.length()];
for(int i=0; i < msg_text.length(); i++) {
msg_chars[i] = "\\" +String.valueOf(String.format("\\u%04x", (int) msg_text.charAt(i)));
}
msg_text = ""
for(int i=0; i < msg_chars.length; i++) {
msg_text += msg_chars[i];
}
@beefy
beefy / funcs.py
Last active May 19, 2016 00:31
Python mathy functions, in no particular order
import math
import operator
# primality test
def is_prime(i):
if i <= 1: return False
if i <= 3: return True
if i%3 == 0 or i%2 == 0: return False
return sum((1 for y in xrange(5, int(i**0.5)+1, 6) if i%y == 0 or i%(y+2) == 0)) == 0
@beefy
beefy / suffix_tree_demo.py
Created May 10, 2016 16:15
A suffix tree class with longest repeated substring implemented
class suffix_tree():
def __init__(self,input_str):
self.root = node(ptr=[])
for i in range(0,len(input_str)):
self.add(self.root,input_str[i:])
# add if input_str never starts with vals in node.ptr
# otherwise, add to node that starts with it
# if a val in node.ptr starts with input_str
@beefy
beefy / crash.py
Created May 12, 2016 13:55
A small python script that will crash your computer (not tested thoroughly)
import itertools
for a,b,c in itertools.product(itertools.count(0),xrange(0,10),xrange(0,10)):
print a,b,c
if a > 20: break
@beefy
beefy / username.py
Created June 2, 2016 15:59
a script to help find a github username
#!/usr/bin/env python2.7
import urllib2
for line in open('/usr/share/dict/cracklib-small','rb'):
try:
urllib2.urlopen('https://github.com/'+line.replace('\n',''))
except urllib2.HTTPError as e:
if e.code == 404:
print line.replace('\n','')
@beefy
beefy / type.py
Created June 3, 2016 16:33
Generate keyboard input, useful if "paste" is unusable
import win32com.client
import time
shell = win32com.client.Dispatch("WScript.Shell")
type_str = 'KexAlgorithms diffie-hellman-group1-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1'
time.sleep(3)
shell.SendKeys(type_str)
@beefy
beefy / bom_encode.py
Last active July 8, 2016 15:40
Reads a file with legacy encoding
# taken from:
# http://stackoverflow.com/questions/22459020/python-decode-utf-16-file-with-bom
def decode_legacy(file_name):
encoded_text = open(file_name,'rb').read()
bom = codecs.BOM_UTF16_LE
assert encoded_text.startswith(bom)
encoded_text= encoded_text[len(bom):]
decoded_text= encoded_text.decode('utf-16le')
return decoded_text
@beefy
beefy / client.js
Last active July 13, 2016 18:38
A simple nodejs/socket.io chat
var socket = require('socket.io-client')('http://127.0.0.1:3000');
socket.on('connect', function(){});
socket.on('event', function(data){});
socket.on('disconnect', function(){});
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
@beefy
beefy / sketch_aug15
Created August 15, 2016 21:47
arduino pulse
void setup()
{
}
void loop()
{
digitalWrite(9,HIGH);
delay(100);
digitalWrite(9,LOW);
delay(900);