Skip to content

Instantly share code, notes, and snippets.

viperscape /
Last active Dec 21, 2015
toml parser for key bindings, example
/// toml parser and config for keybindings, etc.
use toml::{Parser,Value};
use std::fs::File;
use std::io::Read;
use glium::glutin::VirtualKeyCode;
use std::collections::{HashMap,BTreeMap};
pub struct Bindings(HashMap<String,VirtualKeyCode>);
viperscape / night-mode.el
Created Sep 18, 2015
flips between solarized dark/light on keypress
View night-mode.el
(set 'nitemode nil)
(defun toggle-nitemode ()
"toggles nitemode"
(cond ((not nitemode)
(load-theme 'solarized-dark t)
(set 'nitemode 1))
((eq 1 nitemode)
(load-theme 'solarized-light t)
(set 'nitemode nil))))
viperscape /
Created Feb 25, 2015
range in rust, without the need to think about range direction
extern crate core;
use self::core::num::Int;
fn rng<T:PartialEq+Int, F:FnMut(T)> (d:T,dt:T,mut f:F) {
if d>dt { for n in (dt..d).rev() { f(n); } }
else { for n in (d..dt) { f(n); } }
fn main () {
viperscape /
Last active Jun 8, 2016
ec2 snapshot script, max snaps sets revolving snapshots to expire when rerun; expects volume to have tag: snapshot, some-unique-name
import boto.ec2
import sys
def get_snaps (desc, vol,conn):
snapshots = conn.get_all_snapshots(owner='id...',
return snapshots
def op_snaps (vols,max_snaps,conn):
viperscape /
Last active Aug 29, 2015
latch and promise sync primitives
use std::sync::atomic::{AtomicBool,Ordering};
use std::sync::{Arc, RWLock};
struct Latch {
impl Latch {
fn new () -> Latch {
Latch {latch:Arc::new(AtomicBool::new(false))}
viperscape /
Created Nov 16, 2014
nasa-apod download
import urllib.request
address = ''
file = urllib.request.urlopen(address) #read in the site and hunt for the image url
html =
data = html.decode('utf-8')
#print (data)
s = data.find("<a href=\"image")+14 #find the first instance of the image hyperlink
viperscape / github.clj
Created Nov 16, 2014
get gist and git src via github api
View github.clj
(ns github
"pull in github source files and gist content
malformed api calls, invalid resource uri, and rate-limiting should return nil"
(:require [cheshire.core :as json]
[clojure.string :as string])
(:import (org.apache.commons.codec.binary Base64 StringUtils)))
(defn get-gist [gist-uri]
(let [gist-id (last (string/split gist-uri #"/+")) ;;just need id for git api
gist-resp (try (slurp (str "" gist-id))
viperscape / lazy-re.clj
Last active Aug 29, 2015
lazy regex matches
View lazy-re.clj
(defn lazy-re [re pp]
(let [re-m (re-matcher re pp)
re-cm #(re-find re-m)
(fn step []
(when-let [r (re-cm)]
(cons r
viperscape / init.el
Last active Aug 29, 2015
rust lang, cargo/rustc run hotkeys
View init.el
(defun rust-save-compile-and-run-this ()
(format "rustc %s && %s"
(file-name-sans-extension (buffer-file-name)))))
(defun rust-save-compile-and-run ()
viperscape / init.el
Created Nov 12, 2014
toggle cleanmode (no menu,scroll,toolbars)
View init.el
(set 'cleanmode 1)
(defun toggle-cleanmode ()
"toggles clean mode"
(cond ((not cleanmode)
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(set 'cleanmode 1))
((eq 1 cleanmode)
You can’t perform that action at this time.