Skip to content

Instantly share code, notes, and snippets.

View edrex's full-sized avatar

Eric Drechsel edrex

  • Portland, OR
View GitHub Profile
#!/usr/bin/env python
# quickly toggle between brightness levels
# put this in your path and run it using a gnome keyboard shortcut
# i have it bound to Ctrl-F5
import dbus
bus=dbus.SessionBus()
proxy=bus.get_object('org.gnome.PowerManager','/org/gnome/PowerManager/Backlight')
cl = int(proxy.GetBrightness(dbus_interface='org.gnome.PowerManager.Backlight'))
if cl < 20:
class Primes extends Iterable[Int] {
import scala.collection.mutable.ListBuffer
var primes = ListBuffer[Int]()
var ints = Iterator.from(2)
def iterator = new Iterator[Int] {
def hasNext = true
def next:Int = {
ints.dropWhile(n => primes.exists(n % _ == 0))
primes += ints.next
primes.last
@edrex
edrex / README.md
Created February 27, 2012 02:34
Pascal's Triangle Congruence Mod p
@edrex
edrex / graph.json
Created April 11, 2012 06:52 — forked from mbostock/.block
Force-Directed Layout (with labels)
{"nodes":[{"name":"Myriel","group":1},{"name":"Napoleon","group":1},{"name":"Mlle.Baptistine","group":1},{"name":"Mme.Magloire","group":1},{"name":"CountessdeLo","group":1},{"name":"Geborand","group":1},{"name":"Champtercier","group":1},{"name":"Cravatte","group":1},{"name":"Count","group":1},{"name":"OldMan","group":1},{"name":"Labarre","group":2},{"name":"Valjean","group":2},{"name":"Marguerite","group":3},{"name":"Mme.deR","group":2},{"name":"Isabeau","group":2},{"name":"Gervais","group":2},{"name":"Tholomyes","group":3},{"name":"Listolier","group":3},{"name":"Fameuil","group":3},{"name":"Blacheville","group":3},{"name":"Favourite","group":3},{"name":"Dahlia","group":3},{"name":"Zephine","group":3},{"name":"Fantine","group":3},{"name":"Mme.Thenardier","group":4},{"name":"Thenardier","group":4},{"name":"Cosette","group":5},{"name":"Javert","group":4},{"name":"Fauchelevent","group":0},{"name":"Bamatabois","group":2},{"name":"Perpetue","group":3},{"name":"Simplice","group":2},{"name":"Scaufflaire","group":2},
@edrex
edrex / ssh-auto
Last active May 8, 2020 05:47
SSH Auto
#!/bin/sh
# Auto-reconnect ssh screen session after sleep + wifi network change
# usage: ssh-auto user@server
# With these setting SSH will detect a dropped connection after 30 seconds.
# Script will attempt to reconnect every 5 seconds whenever connection is dropped.
# Use Ctrl-C to exit the reconnect loop.
# choose your remote session manager
# ON_CONNECT_CMD='screen -DR'
ON_CONNECT_CMD='tmux -2 attach || tmux -2 new'
@edrex
edrex / create_box_and_sphere_in_new_doc.py
Created September 8, 2012 17:12
FreeCAD Scripting Examples
import FreeCAD
import Part
App.newDocument()
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")
box = App.ActiveDocument.addObject("Part::Box","Box")
box.Placement = App.Placement(App.Vector(1,1,1),App.Rotation(0,0,0,1))
@edrex
edrex / README.md
Created November 5, 2012 22:21 — forked from mbostock/.block
Line Chart
@edrex
edrex / gist:6033528
Created July 18, 2013 22:03
New Mac OOB setup
i Chrome (with Safari)
i Dropbox and start sync
p name this mac
i XCode cmd line tools from OSX dev site (git, make, etc)
i Sublime Text
i iTerm2
r ssh-keygen
r scp -rp othermachine.local:~/.gnupg ~/
i GPG Tools
w upload ssh pubkey to services:
{
"rules": {
".read": true,
"messages": {
".read": true,
"$msg": {
".validate": "newData.child('user_id').val() == auth.id && newData.child('provider').val() == auth.provider",
".write": "!data.exists() && auth != null"
}
}
@edrex
edrex / sitemap.xml.jade
Created November 7, 2013 08:43
Harp sitemap.xml in Jade
doctype xml
- function merge(a,b,pre){for (var f in b) { a[f] = b[f]}; return a}
- function prefix(a,pre){var r={}; for (var f in a) { r[pre+f] = a[f]}; return r}
- function subdirs(b){var r={}; for (var i in b) {if (i !== 'data' && i !== 'contents') r[i]=b[i]}; return r;}
- function all_posts(b,pre){var r=prefix(b.data,pre); for(var s in subdirs(b)){merge(r, all_posts(b[s],pre+s+'/'))}; return r}
urlset(xmlns='http://www.sitemaps.org/schemas/sitemap/0.9')
each val, key in all_posts(public, '/')
url
loc #{key}