Skip to content

Instantly share code, notes, and snippets.

// .. //
static VERT_SRC: &'static str = r"
#version 140
in vec3 pos;
in vec3 norm;
uniform mat4 transform;
uniform vec3 size;
uniform vec3 color;
@viperscape
viperscape / config.rs
Last active December 21, 2015 19:05
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};
#[derive(Debug)]
pub struct Bindings(HashMap<String,VirtualKeyCode>);
@viperscape
viperscape / night-mode.el
Created September 18, 2015 13:14
flips between solarized dark/light on keypress
(set 'nitemode nil)
(defun toggle-nitemode ()
"toggles nitemode"
(interactive)
(cond ((not nitemode)
(load-theme 'solarized-dark t)
(set 'nitemode 1))
((eq 1 nitemode)
(load-theme 'solarized-light t)
(set 'nitemode nil))))
@viperscape
viperscape / rng.rs
Created February 25, 2015 19:18
range in rust, without the need to think about range direction
#![feature(core)]
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
viperscape / ec2-snapshots.py
Last active June 8, 2016 16:54
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...',
filters={'description':'*'+desc+'*'})
return snapshots
def op_snaps (vols,max_snaps,conn):
@viperscape
viperscape / promise.rs
Last active August 29, 2015 14:10
latch and promise sync primitives
use std::sync::atomic::{AtomicBool,Ordering};
use std::sync::{Arc, RWLock};
struct Latch {
latch:Arc<AtomicBool>,
}
impl Latch {
fn new () -> Latch {
Latch {latch:Arc::new(AtomicBool::new(false))}
@viperscape
viperscape / nasa-apod.py
Created November 16, 2014 20:11
nasa-apod download
import urllib.request
address = 'http://apod.nasa.gov/apod/astropix.html'
file = urllib.request.urlopen(address) #read in the site and hunt for the image url
html = file.read()
data = html.decode('utf-8')
#print (data)
s = data.find("<a href=\"image")+14 #find the first instance of the image hyperlink
@viperscape
viperscape / github.clj
Created November 16, 2014 20:00
get gist and git src via github api
(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 "https://api.github.com/gists/" gist-id))
@viperscape
viperscape / lazy-re.clj
Last active August 29, 2015 14:09
lazy regex matches
(defn lazy-re [re pp]
(let [re-m (re-matcher re pp)
re-cm #(re-find re-m)
call-lzre
(fn step []
(lazy-seq
(when-let [r (re-cm)]
(cons r
(step)))))]
(call-lzre)))
@viperscape
viperscape / init.el
Last active August 29, 2015 14:09
rust lang, cargo/rustc run hotkeys
(defun rust-save-compile-and-run-this ()
(interactive)
(save-buffer)
(compile
(format "rustc %s && %s"
(buffer-file-name)
(file-name-sans-extension (buffer-file-name)))))
(defun rust-save-compile-and-run ()
(interactive)