Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
hacking the mainframe

Mark Watson markwatson

💻
hacking the mainframe
View GitHub Profile
@markwatson
markwatson / jwks.json
Last active Oct 6, 2022
testjwk.json
View jwks.json
[{"crv":"P-256","x":"AK8tZe41dys_C6BTzKdueyB4aZ4Wf-PCujzb7j3i7m2d","y":"Ziv-DVie-hMW4GV9jzlPqs77nsu0Msh0-TU3lgXUdE0=","kty":"EC","use":"sig","keyOps":["sign","verify"],"alg":"ES256","kid":"arn:aws:kms:us-east-1:000000000000:key/0d134cc0-7bd3-48a9-89eb-e7cfb0188b41"}]
View lagrange.py
# Tested on Windows 7 and Python 2.7
# the code
def lagrangian_interpolate(samples):
"""
Takes some samples as a list of tuples and returns a function that's
a lagrangian interpolation of all the samples.
"""
X = 0 # the tuple index of the X variable in the samples
Y = 1 # the tuple index of the Y variable in the samples
@markwatson
markwatson / knapsack.scala
Created Feb 11, 2012
Branch and Bound Knapsack Solution
View knapsack.scala
// Branch and bound knapsack problem
import collection.mutable.PriorityQueue
/** This class represents a thing we can put in the napsack.
*/
class Thing(wIn:Int, vIn:Int) extends Ordered[Thing] {
val w = wIn
val v = vIn
def v_w = v / w
override def toString = "w=%d, v=%d, v/w=%d".format(w, v, v_w)
@markwatson
markwatson / keybase.md
Created Jan 3, 2018
Keybase verification
View keybase.md

Keybase proof

I hereby claim:

  • I am markwatson on github.
  • I am markwatson (https://keybase.io/markwatson) on keybase.
  • I have a public key ASCuAq64t3gLeQezhPXltcKBo12vkezVThpaCWjAF65M2Ao

To claim this, I am signing this object:

View Dmoz.py
import mechanize
from BeautifulSoup import BeautifulSoup
class Dmoz(object):
def __init__(self):
self.br = mechanize.Browser()
def get_page_urls(self, term):
result = self.br.open("http://www.dmoz.org/search?q="+term)
result_html = result.read()
@markwatson
markwatson / toString Generator
Created Feb 9, 2016 — forked from jenslohmann/toString Generator
Java toString() generator for IntelliJ IDEA that generates JSON
View toString Generator
public java.lang.String toString() {
#if ( $members.size() > 0 )
#set ( $i = 0 )
return "{\"_class\":\"$classname\", " +
#foreach( $member in $members )
#set ( $i = $i + 1 )
#if ( $i == $members.size() )
#set ( $postfix = "+" )
#else
#set ( $postfix = "+ "", "" + " )
@markwatson
markwatson / time_card.py
Created Jul 16, 2013
A simple time tracker script.
View time_card.py
#/usr/bin/env python
"""
time_cards.py
This utility tracks time.
"""
import datetime
import atexit
@markwatson
markwatson / merge_tuples.rb
Created Mar 11, 2013
Merges an array of arrays by adding the elements together.
View merge_tuples.rb
# Takes an array of totals_tuples and combines them into a single tuple.
def self.merge_tuples(tuples)
tuples.inject([]) do |xs, ys|
l = [xs.length, ys.length].max
zs = []
l.times.each do |i|
zs[i] = (xs[i] || 0) + (ys[i] || 0)
end
zs
end
@markwatson
markwatson / pretty_json.py
Last active Dec 12, 2015
A sublime text plugin that pretty formats all the select JSON blobs.
View pretty_json.py
import sublime, sublime_plugin
import json
import re
class PrettyJsonCommand(sublime_plugin.TextCommand):
def run(self, edit):
re_json_p = re.compile(r'^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$')
try:
for region in self.view.sel():
@markwatson
markwatson / stats.py
Created May 3, 2012
Random stats functions
View stats.py
def mean(x): return sum(x) / len(x)
def std_dev(x, mx=None):
if mx is None:
mx = mean(x)
return math.sqrt(sum((i - mx)**2 for i in x)/len(x))