Skip to content

Instantly share code, notes, and snippets.

View crankycoder's full-sized avatar

Victor Ng crankycoder

View GitHub Profile

{ "body": { "key": { "eldest_kid": "0120f6e10574deeefaf8a68b284bb1f027683ff28c757cd025010c20ad5ffe13556c0a", "host": "keybase.io", "kid": "0120f6e10574deeefaf8a68b284bb1f027683ff28c757cd025010c20ad5ffe13556c0a", "uid": "1937bc2ddd1811722f0efa789b0c2419", "username": "crankycoder" }, "merkle_root": {

@crankycoder
crankycoder / goldensection.py
Created October 27, 2010 17:39
A demonstration of the golden section search algorithm
from math import sqrt
phi = (1 + sqrt(5))/2
resphi = 2 - phi
# a and b are the current bounds; the minimum is between them.
# c is the center pointer pushed slightly left towards a
def goldenSectionSearch(f, a, c, b, absolutePrecision):
if abs(a - b) < absolutePrecision:
return (a + b)/2
# Create a new possible center, in the area between c and b, pushed against c
@crankycoder
crankycoder / Vision (colorblind) (rainglow).itermcolors
Last active May 28, 2021 17:40
Colorblind palette for iTerm2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.050980392156862744</real>
<key>Green Component</key>
<real>0.050980392156862744</real>
@crankycoder
crankycoder / setup-pyenv-ubuntu-20.sh
Last active May 27, 2021 02:48
Setup pyenv for ubuntu 20 distros
#!/bin/bash
sudo apt-get install git python-is-python3 python3-pip make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl
sudo pip install virtualenvwrapper
# Official pyenv repos are under github.com/yyuu
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
git clone https://github.com/yyuu/pyenv-virtualenvwrapper.git ~/.pyenv/plugins/pyenv-virtualenvwrapper
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
@crankycoder
crankycoder / mad.py
Created October 30, 2019 15:59
MAD Cat
'''
Run this with:
env FLASK_APP=foo.py flask run
.
|'.._ __......._ _.-'.
\M\ ^'.-' ''-/ /
-bash-4.2$ pytest
========================================= test session starts ==========================================
platform linux2 -- Python 2.7.12, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/hadoop/taar, inifile:
plugins: cov-2.5.1
collected 24 items
test_collaborativerecommender.py ....
test_legacyrecommender.py ...
test_localerecommender.py ....
@crankycoder
crankycoder / smartplug.py
Created June 8, 2016 21:46 — forked from arminwasicek/smartplug.py
Simple library/command-line-utility to control a EDIMAX Smart Plug Switch (SP-1101W) from Python
##
# The MIT License (MIT)
#
# Copyright (c) 2014 Stefan Wendler
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@crankycoder
crankycoder / building-static-nginx.txt
Created May 26, 2016 01:36 — forked from rjeczalik/building-static-nginx.txt
Notes on building nginx as a static binary.
# Building static nginx for teh lulz
#
# basic dependencies
sudo apt-get install libxslt1-dev libxml2-dev zlib1g-dev libpcre3-dev libbz2-dev libssl-dev
# download nginx and openssl
wget http://nginx.org/download/nginx-1.5.6.tar.gz
tar xf nginx-1.5.6.tar.gz; cd nginx-1.5.6

Save books out of Safari Books Online

From http://objectivesea.tumblr.com/post/9033067018/safaribooks

This is hard. I spent way too much time figuring this out, because I was annoyed that a book I bought (Addison-Wesley) was available online for free, except only for 45 days after which payment was required. So I made this hack... probably useful to no one else, but here it is.

Requirements:

  1. iPad.
  2. Safari To Go (the Safari Books Online iPad app).
@crankycoder
crankycoder / gist:7606676
Created November 22, 2013 20:52
TOML config to debug syslog over UDP problems
[UdpInput]
address = "127.0.0.1:2514"
parser_type = "packet"
decoder = "syslog_sandbox"
[syslog_sandbox]
type = "SandboxDecoder"
script_type = "lua"
filename = "/tmp/syslog_decoder.lua"
timestamp_field = "syslog_ts"