Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / README.md
Created August 18, 2012 14:16
MODX + Monolog

MODX Revolution + Monolog

Replace MODX logging with Monolog to log to Graylog2, syslog, AMQP, etc.

Installation

  • put all the contents of this gist into the document root (where folders core, manager, etc. are located)
  • run composer install to get Monolog
  • run sh patchmodx.sh
  • edit modx-monolog.php - at line 22 there's the default handler - replace it with whatever you want to log to - see monolog readme for more info