Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kzahel's full-sized avatar

Kyle Graehl kzahel

View GitHub Profile
@kzahel
kzahel / download-fonts.py
Created February 24, 2017 00:03
download fonts
import json
import os
""" to get the following string, i went to https://google-webfonts-helper.herokuapp.com/fonts/abeezee?subsets=latin and opened devtools and typed
a=document.querySelectorAll('a.list-group-item')
for (var i=0; i<a.length ; i++) { ah.push(a[i].href) }
JSON.stringify(ah)
import collections
class LRUCache:
def __init__(self, capacity):
self.capacity = capacity
self.cache = collections.OrderedDict()
def get(self, key):
try:
value = self.cache.pop(key)
@kzahel
kzahel / delete-dsstore-etc.sh
Created October 9, 2016 18:21
delete .DS_Store and the other extended files ._*
WHAT="rm"
#WHAT="echo" #uncomment this for dry run
echo "Going to remove mac extended files in $1"
read -p "press enter key to continue"
find $1 -type f -name "._*" -exec $WHAT "{}" \;
find $1 -type f -name ".DS_Store" -exec $WHAT "{}" \;
@kzahel
kzahel / replace.py
Created September 4, 2016 01:32
replace recursive text exclude .git directory
import os, fnmatch
def findReplace(directory, find, replace, filePattern):
for path, dirs, files in os.walk(os.path.abspath(directory), topdown=True):
dirs[:] = [d for d in dirs if d not in '.git']
for filename in fnmatch.filter(files, filePattern):
filepath = os.path.join(path, filename)
with open(filepath) as f:
s = f.read()
s = s.replace(find, replace)
with open(filepath, "w") as f:
@kzahel
kzahel / gist:6eb6ebaa7a495e7329bc0392305a2db3
Last active May 5, 2016 01:11
function wait_for_devtools
function wait_for_devtools( callback, giveup_after ) {
giveup_after = giveup_after || 10
var start = Date.now()
var timeout
var triggered = false
var element = new Image();
element.__defineGetter__('id', done)
function done() {
if (triggered) return ''
<html>
<body>
<audio id="myaudio" preload="auto" src="data:audio/wav;base64,UklGRiZvAABXQVZFZm10IBAAAAABAAEAESsAABErAAABAAgAZGF0YQJvAACAgoaJjIuJiIuNkZSXmZqdn52bnJ6hoqGhoqOko6CenqGkpaepq62uraqoqKmppqKfn52alpKQkZSTkIuKiYaDf318fX5+e3l4eHZzc3R3en+Afn6Ag4OCgoWHio2NjIuKiIWDhIeKjI2MiYWBf3x7foKEhYSCfn19fn+Ch4uNjYuIhYSDgYKEh4mJiYeFgoKBgIKEhYWEg4J/fn2AhIuPkI+NiYeFg4OFhoiGhIGAfn+Af4CDhYaEg4KAgYKBgYSHiYeGhYSDgoB/fXx7eHRwbm5ub3FydHV3dnV1eX2BhYmOkZWVlpeYmp2gpKipp6akoZ6bmJWVl5eWk5CLh4aEhIKDhISAenVvbGtoZGJjYmFcVlNSVFNQTlBRUU1HQkBCRUZGR0tOTkxGQ0ZKTU5OUVVXVE5LS09RUVBRVVdXUk1NUVVYWFldYmNfWlpeYWRmaWxxcnFubG5ydHV2d3h3dXFubnF0dHJyc3JycGxtcXl9gIGBg4WDf3x8gISFhoeJiYeCgH+Ei46NjYyLiYeEgYSJjo+PkJGRkI2MjpOWl5WVlZaVko+Qk5iYlJGQj42Jh4eKjYyHhIODhIF+fX+ChIJ8eHd2dHJxc3Z4eHZ0dnd4d3h6foKCgICAgH97eHd3dXNvbG1ub25qZ2lraGNfXV5hX11cXV5gXl1dYGNmZ2psb29uamhoamtqamlpZ2JcV1dYWlteYGRmZ2NfYGNmbHBydnd2cWtoam1wdXd4eXx5dnR0d3h7fH6AgoJ+eXR0c3N2e3+CgoB5dXR2d3p+hIiJiYaDgoSJkZifpqmqq6qoqKiprLC1uLi1r6mlpaanqq+ztLGro5uYlpeZmpydnJaOh4KCgYODhYiJiIR/fX1/
@kzahel
kzahel / auto indent
Created May 3, 2016 03:35
emacs on 14.04
to get previous behavior:
(define-key global-map (kbd "RET") 'newline-and-indent)
now why would they go and change the default of enter key? :-)
@kzahel
kzahel / gist:1530ce5e00a7124bff60c8f91324eda8
Last active March 30, 2023 20:36
ChromeOS sshd openssh server
sudo su
apt-get install -y openssh-server iptables
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
mkdir -p -m0755 /var/run/sshd
/usr/sbin/sshd
#
ssh -o VisualHostKey=yes -o FingerprintHash=md5 {host}
The authenticity of host '{host} (ip)' can't be established.
ECDSA key fingerprint is MD5:f9:8d:d8:fc:93:7a:fb:1e:90:a2:4c:49:26:ef:cf:d1.
+---[ECDSA 256]---+
| |
| |
| . o |
| = o . |
| S . o |
| + * = . |
@kzahel
kzahel / nested_async_yield
Created September 27, 2012 21:53
nested async yield
def asyncsleep(t, callback=None):
ioloop.add_timeout( time.time() + t, callback )
class NestedYieldAsync(tornado.web.RequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def get(self):
yield gen.Task( self.lots_of_waits )
yield gen.Task( self.lots_of_waits )