Skip to content

Instantly share code, notes, and snippets.

@valpackett
valpackett / gist:4142920
Created November 25, 2012 09:26
Slate ASCIIToCode generator example
# use:
# cat Slate/ASCIIToCode.plist | head -n -2 | tail -n +5 | python gen_c.py > Slate/ASCIIToCode_Colemak.plist
import re
import sys
def iter_pairs(a):
for i in range(len(a))[::2]:
yield(a[i], a[i+1])
@valpackett
valpackett / MergeScreenshots.py
Last active December 10, 2015 11:48
MergeScreenshots
# Universal screenshot merger for Pythonista.
# Takes any number of screenshots,
# downscales if Retina,
# merges.
#
# by Greg V <http://floatboth.com>
# Settings:
margin = 15 # pixels
@valpackett
valpackett / ClojureEval.py
Created January 5, 2013 09:58
ClojureEval
# TryClojure - Eval from clipboard
import clipboard
import requests
d = {'expr': clipboard.get()}
r = requests.get('http://tryclj.com/eval.json', params=d)
if 'result' in r.json:
print(r.json['result'])
else:
@valpackett
valpackett / ClojureRepl.py
Created January 5, 2013 09:58
ClojureRepl
# TryClojure - REPL
import requests
while True:
d = {'expr': raw_input()}
r = requests.get('http://tryclj.com/eval.json', params=d)
if 'result' in r.json:
print(r.json['result'])
else:
@valpackett
valpackett / viewport-fix.js
Created January 5, 2013 17:40
Landscape viewport fix (i.e. makes it 1024px on landscape iPad, 480px on landscape iPhone)
if (typeof window.orientation !== 'undefined') {
var viewport = document.querySelector('meta[name=viewport]');
function isLandscape() {
return window.orientation === 90 || window.orientation === -90;
}
function fixViewport() {
if (isLandscape()) { viewport.content = 'width=device-height' }
else { viewport.content = 'width=device-width' }
}
fixViewport();
@valpackett
valpackett / require-me-maybe.clj
Last active December 14, 2015 15:49
Clojure macro for executing code if a library exists
(defmacro when-require [n & body]
(let [nn (eval n)]
(try (require nn)
(catch Throwable e nil))
(when (find-ns nn)
`(do ~@body))))
(defmacro if-require [n body1 body2]
(let [nn (eval n)]
@valpackett
valpackett / Alfred-Pinboard-INSTANT.md
Last active September 7, 2023 21:01
INSTANT Pinboard search from Alfred 2

INSTANT Pinboard search from Alfred 2

I've had a Python script that makes an HTML Bookmarks file for LaunchBar.
Now that I use Alfred 2, I modified it to make XML for Alfred.
This allows me to search my bookmarks with GREP SPEED!

Installation

First, add your token (from pinboard.in/settings/password) to ~/.netrc

@valpackett
valpackett / Gemfile
Last active December 19, 2015 09:09
Ruby: async & thread pool under one EventMachine server
source 'http://rubygems.org'
gem 'thin'
gem 'celluloid'
@valpackett
valpackett / sandboxed_computation.rs
Last active February 15, 2016 19:46
Early prototype of rusty-sandbox, using a shared memory arena like in sandblast
extern crate libc;
use std::{io, process, mem, ptr};
pub struct Shared<T> {
data: *mut T
}
pub struct SharedArena {
max_size: isize,
@valpackett
valpackett / rename_to_timestamp.rb
Created March 5, 2016 14:05
Convert Sweetroll entires' file names to new, date-based format
%w(date json).each { |m| require m }
Dir[File.join ARGV.first, "**/*.json"].each do |path|
fname = File.basename(path)
next if (fname =~ /^\d+-.*/).nil?
pub = (JSON.parse(File.read(path))["properties"] || {})["published"] || []
next if pub.empty?
newpath = File.join File.dirname(path), fname.gsub(/^\d+/, DateTime.parse(pub.first).strftime("%s"))
puts "#{path} => #{newpath}"
File.rename path, newpath
end