Skip to content

Instantly share code, notes, and snippets.

View stewartpark's full-sized avatar
🏠
Working from home

Stewart Park stewartpark

🏠
Working from home
View GitHub Profile
@stewartpark
stewartpark / test.java
Created May 25, 2013 09:11
Hello world!
import java.lang.*;
import java.lang.reflect.*;
public class test extends ClassLoader{
byte[] b = {(byte)0xCA,(byte)0xFE,(byte)0xBA,(byte)0xBE,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x32,(byte)0x00,(byte)0x1D,(byte)0x0A,(byte)0x00,(byte)0x06,(byte)0x00,(byte)0x0F,(byte)0x09,(byte)0x00,(byte)0x10,(byte)0x00,(byte)0x11,(byte)0x08,(byte)0x00,(byte)0x12,(byte)0x0A,(byte)0x00,(byte)0x13,(byte)0x00,(byte)0x14,(byte)0x07,(byte)0x00,(byte)0x15,(byte)0x07,(byte)0x00,(byte)0x16,(byte)0x01,(byte)0x00,(byte)0x06,(byte)0x3C,(byte)0x69,(byte)0x6E,(byte)0x69,(byte)0x74,(byte)0x3E,(byte)0x01,(byte)0x00,(byte)0x03,(byte)0x28,(byte)0x29,(byte)0x56,(byte)0x01,(byte)0x00,(byte)0x04,(byte)0x43,(byte)0x6F,(byte)0x64,(byte)0x65,(byte)0x01,(byte)0x00,(byte)0x0F,(byte)0x4C,(byte)0x69,(byte)0x6E,(byte)0x65,(byte)0x4E,(byte)0x75,(byte)0x6D,(byte)0x62,(byte)0x65,(byte)0x72,(byte)0x54,(byte)0x61,(byte)0x62,(byte)0x6C,(byte)0x65,(byte)0x01,(byte)0x00,(byte)0x04,(byte)0x6D,(byte)0x61,(byte)0x69,(byte)0x6E,(byte)0x01,(byte)0x00,(byte)0x
@stewartpark
stewartpark / p381.py
Last active August 29, 2015 13:56
Projecteuler.net Problem 381
#!/usr/bin/env python
"""
Projecteuler
Problem 381
Wilson's theorem
"""
import fastlib
import math
#!/usr/bin/env python
# This is an example Git server. http://blog.nerds.kr/post/106956608369/implementing-a-git-http-server-in-python
# Stewart Park <stewartpark92@gmail.com>
from flask import Flask, make_response, request, abort
from StringIO import StringIO
from dulwich.pack import PackStreamReader
import subprocess, os.path
from flask.ext.httpauth import HTTPBasicAuth
@stewartpark
stewartpark / blanace.py
Last active April 20, 2016 21:44
Foo.bar peculiar balance
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
$ time python balance.py
1133135930 ['L', 'R', 'R', 'R', 'L', 'R', 'R', 'L', 'R', 'L', 'L', 'R', 'L', '-', '-', 'R', 'L', '-', '-', 'R']
python balance.py 0.02s user 0.01s system 91% cpu 0.032 total
"""
def inc_one_digit(n):
if n == 'L':
@stewartpark
stewartpark / zombit.py
Last active August 29, 2015 14:23
Foo.bar zombit monitoring
def intersect(P, i):
ps = []
for p in P:
if p[0] <= i[0] and p[1] >= i[0]:
ps.append(p)
elif p[0] <= i[1] and p[1] >= i[1]:
ps.append(p)
elif p[0] >= i[0] and p[1] <= i[1]:
ps.append(p)
return ps
@stewartpark
stewartpark / gist:ed4327df81accd192bf2
Created October 11, 2015 20:01
taco-recommend.md
Ezpz. :D
https://taco-spolsky.github.io/?____valueOf#|checksum=9284326|Stewart Park=
@stewartpark
stewartpark / hashitout.py
Created October 11, 2015 21:32
Foo.bar hash it out
#!/usr/bin/env python
def memoize(f):
memo = {}
def helper(*args):
x = str(args)
if x not in memo:
memo[x] = f(*args)
return memo[x]
return helper
from __future__ import print_function
from collections import OrderedDict
N = input()
raw_records = map(lambda x: raw_input(), xrange(N))
records = OrderedDict()
# Since the syntactic correctness is given in the example, and also the order of the names can be simplified to the length of the name,
occurence = lambda x, y: len(x) - len(x.replace(y, ''))
order = lambda x: (10 * len(x.split())) - occurence(x, '.')
@stewartpark
stewartpark / xor.py
Created October 12, 2015 08:17
Simple XOR learning with keras
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import SGD
import numpy as np
X = np.array([[0,0],[0,1],[1,0],[1,1]])
y = np.array([[0],[1],[1],[0]])
model = Sequential()
model.add(Dense(8, input_dim=2))
@stewartpark
stewartpark / xor_dec.py
Created October 13, 2015 16:21
Foobar password decryption
#!/usr/bin/env python3
from functools import lru_cache
"""
The encryption equation is given as:
D_i = (129M_i) XOR (M_(i-1)) (mod 256)
where D denotes a encrypted string, M is the message.
Thus, the message equation derived from the original equation should be: