Skip to content

Instantly share code, notes, and snippets.

View rgegriff's full-sized avatar

George Griffin rgegriff

  • NYC
View GitHub Profile
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCx8ZUCABe1f8SEF8nNZD/zjEJhAS7YlL1CYSASEC7FZuryrzbzIJ9Oz+sCGDtQeQufTss7v216ODuWByIdW9GoZMCt60mZIGh6MarbkCLaV2kDiRmdtQ1SkXo1FRnPYpgX/3W+1RvVMG8yHLAszGxryQfgRfz4mNAc8EciS60uQ1khuJz15WP2LZf+JQQlqk1+hklhmWnqZxt6ZrlZZh0uRSC7aGW2ObHl4bDVBDAUHKPEJp0+aw8NuQwDX2bflm+uCt9A3eR3oaZvv7+HmC7hJio2hDZH+AyP9jqZfmWFyWqR3ltEJHuMa9kFBo2r/RCzGT83QSo5xJvCuHLlFs/KT1+qLzVfUzPX6SI5lglnQQTuGtMs6eD/0klxwff9CigKGzoXacEw7LX6SxnCSGDaCwLafS9zdENXjJE8rOlC88ZuHB0i8jZRYeaEGgyK0Gr7Qv4FmzWehMhCI0zT6EgrXe1F8vFnLPl6kGByvFlVCVmVYkPTc9EFG6kcE9TVBHM= george@Georges-MBP
def is_palindromatic(num):
'''returns true if passed int is palindromatic'''
return str(num) == str(num)[::-1]
# Demonstrating my lazi--- I mean ability to reuse code
def palingen():
'''go through all the ints, and yield the palindromatic ones'''
val = -1
while True:
val += 1
# there is a more straightforward solution, but this test is boring, so here's a generator-based version :P
# Fibonacci generator
def fibgen():
'''generator that yields fibonacci numbers'''
yield 0
crnt = 0
nxt = 1
while True:
crnt, nxt = nxt, crnt+nxt
yield crnt
<div class="content">
<div class="news_col news_leftcol">
<div class="ukulele">
<h2>Gawgs gets an acoustic pickup for his uke.</h2>
<p>"I hope you like ukuleles because I'm gonna play it in a lot of my songs."
- Gawgs</p>
<p>6/28/2020</p>
</div>
</div>
<div class="news_col news_rightcol">
@rgegriff
rgegriff / linearize_dict.py
Last active June 10, 2020 19:18
Code for walking a nested dictionary in python and turning it into a flat dictionary with dotted key names
def linearize_dict(dct, prefix=None, part_sep="."):
"""Walk a nested dict, and flatten it"""
linearized = {}
for key, value in dct.items():
# Ensure key doesn't already contain part_sep
if part_sep in key:
raise Exception("Part sep '%s' exists in key. Use a different part sep")
# Create prefixed version of this key if needed
if prefix == None:
prefixed_key = key
@rgegriff
rgegriff / encoders.py
Last active February 11, 2021 19:30 — forked from majgis/encoders.py
JSON Encoder and Decoder for datetime and timedelta
# Taken from http://taketwoprogramming.blogspot.com/2009/06/subclassing-jsonencoder-and-jsondecoder.html
from json import JSONEncoder, JSONDecoder
class DateTimeAwareJSONEncoder(JSONEncoder):
"""
Converts a python object, where datetime and timedelta objects are converted
into objects that can be decoded using the DateTimeAwareJSONDecoder.
"""
def default(self, obj):
if isinstance(obj, datetime):
return {
@rgegriff
rgegriff / keybase.md
Last active October 5, 2017 17:43
Keybase POI

Keybase proof

I hereby claim:

  • I am rgegriff on github.
  • I am rgegriff (https://keybase.io/rgegriff) on keybase.
  • I have a public key ASBfFcZZKOYE2M-VnlqScrCMRcm4tuxGoxVityido0wxFgo

To claim this, I am signing this object:

[sdl]
fullscreen=false
fulldouble=false
fullresolution=400x250
windowresolution=400x250
output=overlay
autolock=false
sensitivity=100
waitonerror=true
@rgegriff
rgegriff / impersonate.py
Created August 1, 2016 21:32
Impersonate python sessions
email = "User@email.com"
user = User.objects.get(email__icontains=email)
[s for s in Session.objects.all() if "_auth_user_id" in s.get_decoded() and int(s.get_decoded()['_auth_user_id']) == user.id]
def mesij_decode(s):
s = s.replace("\r\n","")
normal = '~'+string.uppercase+string.lowercase+string.digits+"+/"
rev = "".join(reversed(normal))
rev = "="+rev[:-1]
transtab = string.maketrans(normal, rev)
ts = string.translate(s, transtab)
print normal+"\n"+rev+"\n"+s+"\n"+ts
return base64.b64decode(ts)