Skip to content

Instantly share code, notes, and snippets.

@simonster
simonster / CSL JSON.js
Created December 6, 2011 08:01
CSL JSON translator (WIP)
{
"translatorID": "bc03b4fe-436d-4a1f-ba59-de4d2d7a63f7",
"label": "CSL JSON",
"creator": "Simon Kornblith",
"target": "json",
"minVersion": "3.0b3",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 3,
@simonster
simonster / gist:1579282
Created January 8, 2012 18:45
Making a new custom document property
// PY-APPSCRIPT
self.asApp.make(new=k.custom_document_property, at=self.asDoc, with_properties={k.name:docPropertyName, k.value:docPropertyValue})
// SCRIPTING BRIDGE
NSAppleEventDescriptor *rd = [NSAppleEventDescriptor recordDescriptor];
[rd setDescriptor:[NSAppleEventDescriptor descriptorWithString:currentPropertyName] forKeyword:'pnam'];
[rd setDescriptor:[NSAppleEventDescriptor descriptorWithString:currentPropertyValue] forKeyword:'DPVu'];
[doc->sbApp sendEvent:'core' id:'crel' parameters:'kocl', @"mCDP", 'insh', doc->sbDoc, 'prdt', rd];
@simonster
simonster / arcs.py
Created April 4, 2012 04:43
Arcs in PostScript
#!/usr/bin/python
LINE_WIDTH = 2;
CIRCLE_RADIUS = 6
IMG_SIZE = 16;
NUM_ARCS = 20;
import subprocess;
p = subprocess.Popen(["gs", "-dSAFER", "-dNOPAUSE", "-r72", "-sDEVICE=pngalpha",
"-sOutputFile=arcs.png", "-"], stdin=subprocess.PIPE);
@simonster
simonster / gist:2920373
Created June 12, 2012 21:56
Asynchronous bottom-up merge sort in JavaScript
var AsyncComparator = function(list) {
this.listsAtCurrentLevel = [];
this.listsAtNextLevel = [];
this.listMerged = [];
for(var i=0; i<list.length; i++) {
this.listsAtCurrentLevel[i] = [list[i]];
}
};
AsyncComparator.prototype.getA = function() {
@simonster
simonster / gist:4712293
Created February 5, 2013 05:05
Modified RDF attachment export example
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:res="http://purl.org/vocab/resourcelist/schema#"
xmlns:z="http://www.zotero.org/namespaces/export#"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:address="http://schemas.talis.com/2005/address/schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:bibo="http://purl.org/ontology/bibo/"
xmlns:link="http://purl.org/rss/1.0/modules/link/">
<z:UserItem rdf:about="http://zotero.org/users/67180/items/4BUASI6R">
@simonster
simonster / gist:5864205
Last active December 18, 2015 23:49
JLD mmap benchmark
using HDF5, JLD
const MATRIX_SIZE = 1000
# Write test file
x = rand(MATRIX_SIZE, MATRIX_SIZE)
jld = jldopen("test.jld", "w")
write(jld, "x", x)
close(jld)
macro s()
@simonster
simonster / gist:6147815
Created August 3, 2013 20:08
Julia vectorization
julia> f(x) = for i = 1:length(x); @inbounds x[i] *= 2; end
# methods for generic function f
f(x) at none:1
julia> disassemble(f, (Matrix{Float64},))
define void @julia_f(i8**) {
top:
%1 = getelementptr i8** %0, i64 2, !dbg !3364
%2 = load i8** %1, align 8, !dbg !3364
@simonster
simonster / gist:6147959
Created August 3, 2013 21:00
IR with jl_value_t -> i8*
define void @julia_f(i8**, i64) #2 {
top:
%2 = icmp slt i64 %1, 1, !dbg !3364
br i1 %2, label %L2, label %if.lr.ph, !dbg !3364
if.lr.ph: ; preds = %top
%3 = getelementptr i8** %0, i64 1, !dbg !3369
%4 = load i8** %3, align 8, !dbg !3369
%5 = bitcast i8* %4 to double*, !dbg !3370
br label %if, !dbg !3364
define void @julia_f(%jl_value_t*, i64) #2 {
top:
%2 = icmp slt i64 %1, 1, !dbg !3364
br i1 %2, label %L2, label %if.lr.ph, !dbg !3364
if.lr.ph: ; preds = %top
%3 = getelementptr inbounds %jl_value_t* %0, i64 1, i32 0, !dbg !3369
%4 = load %jl_value_t** %3, align 8, !dbg !3369
br label %if, !dbg !3364
@simonster
simonster / gist:6157543
Created August 5, 2013 17:01
Loop vectorizer benchmarks
Commit 5d05a4876df53257c7fde518ab3598cf9adeb6f9
➜ perf>make
fib 0.103 0.105 0.104 0.001
parse_int 0.332 0.344 0.338 0.005
mandel 0.332 0.338 0.334 0.003
quicksort 0.495 0.512 0.503 0.007
pi_sum 48.416 56.452 51.751 3.129
rand_mat_stat 48.037 70.606 59.050 9.001
rand_mat_mul 79.485 129.067 98.886 20.258
printfd 47.455 73.397 54.434 10.801