Skip to content

Instantly share code, notes, and snippets.

@arian
arian / index.js
Created October 9, 2015 14:11
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var slick = require('slick');
var sMyString = "<foo><bar></bar></foo>";
var oParser = new DOMParser();
var oDOM = oParser.parseFromString(sMyString, "text/xml");
console.log(slick('bar', oDOM));
@arian
arian / svn
Last active January 18, 2016 15:44
svn tools
#!/bin/sh
usage () {
cat <<USAGE
Helper commands:
tags - List all tags relevant to this trunk
branches - List all branches relevant to this trunk
tag - Tag a trunk or branch copy.
branch - Branch a trunk or tag working copy.
@arian
arian / church.js
Last active September 12, 2021 21:42
Church Numerals, Booleans, Pairs and Lists in JavaScript (ES6)
// conversions
let c2i = x => x(y => y + 1, 0)
let c2star = x => x(y => y + '*', '')
let c2b = x => x('True', 'False')
let c2a = xs => xs((y, ys) => [c2i(y)].concat(ys), [])
// numbers
let zero = (s,z) => z
let one = (s,z) => s(z)
@arian
arian / quicksort.go
Last active August 29, 2015 14:06
Quicksorts
package main
import "fmt"
func quicksort(list []int) []int {
l := len(list)
if (l <= 1) {
return list
}
@arian
arian / fun.js
Last active August 28, 2016 05:31
Functional JS
"use strict";
function toArray(thing) {
if (Array.isArray(thing)) return thing;
return Array.prototype.slice.call(thing);
}
function head(arr) {
return arr[0];
}
var filter = require('prime/array/filter');
var slice = Array.prototype.slice;
var curry = function(fn){
var args = slice.call(arguments, 1);
return function(self){
fn.apply(null, [self].concat(args);
};
};
(function () {
var modules = {}, cache = {};
if (typeof define == 'undefined') {
window.define = function (id, factory) {
modules[id] = factory;
};
window.require = function (id) {
var module = cache[id];
if (!module) {
module = cache[id] = {};
@arian
arian / build.sh
Created April 1, 2013 00:10
Using Prime in gjs to create Gtk Applications.
# use the split-generics branch of prime.
wrup -r prime ../../www/prime/index.js -r bind ../../www/prime/function/bind -o prime.js
@arian
arian / multiply.js
Last active December 14, 2015 20:09
How Hardware multiplies unsigned integers
function multiply(multiplicant, multiplier){
var product = 0;
for (var i = 0; i < 32; i++){
product += (multiplier & 1) ? multiplicant : 0;
multiplicant <<= 1;
multiplier >>= 1;
}
@arian
arian / selection-sort.asm
Created February 27, 2013 16:35
Selection Sort in MIPS assembly, for, I don't know, your PSP?
.text
j main # Jump to main-routine
.data
str1: .asciiz "Insert the array size \n"
str2: .asciiz "Insert the array elements,one per line \n"
str3: .asciiz "The sorted array is : \n"
str5: .asciiz "\n"
.text