Skip to content

Instantly share code, notes, and snippets.

function git_prompt {
local STATUS=`git status 2>&1`
if [[ "$STATUS" != *'Not a git repository'* ]]
then
if [[ "$STATUS" == *'working directory clean'* ]]
then
echo -e "\033[0;32m$(__git_ps1)\033[m"
else
echo -e "\033[0;31m$(__git_ps1)\033[m"
@arian
arian / Slick.Finder-lite.js
Created January 18, 2012 00:10
A lite version of Slick.Finder for modern browsers/mobile.
/*
---
name: Slick.Finder
description: The new, superfast css selector engine.
provides: Slick.Finder
requires: Slick.Parser
...
*/
(function(){
function filePermissionsToNumber(perms){
var result = 0;
var parts = perms.split('');
if (parts[0] == 'r') result += 400;
if (parts[1] == 'w') result += 200;
if (parts[2] == 'x') result += 100;
if (parts[3] == 'r') result += 40;
@arian
arian / ga.js
Created November 10, 2011 14:57
var Rand15 = function(){
return Math.floor(Math.random() * 16);
};
var share = function(arr){
var sum = 0;
for (var i = arr.length; i--;) sum += arr[i];
return arr.map(function(value){ return value / sum; });
};
var Getable = new Class({
get: function(key){
if (Array.isArray(key)){
var result = {};
for (var i = 0; i < key.length; i++){
result[key[i]] = this.get(key[i]);
}
return result;
}
@arian
arian / collegedownloader.sh
Last active June 5, 2017 21:05
Download TU Delft Collegerama video streams, Silverlight player sucks.
#!/bin/bash
slides=1;
video=1;
for var in "$@"
do
if [ "${var}" = "--slidesOnly" ]; then
video=0;
@arian
arian / MilkObserverPattern.js
Created October 31, 2011 03:11
Yet Another Event Pattern proposal
// Observerable Mixin
var ObserverableSubject = new Class({
on: function(type){
var observerables = (this._observerables || (this._observerables = {}));
var observerable = observerables[type];
if (!observerable){
var _Observerable = this.constructor.lookupObserverable(type);
if (!_Obseverable) throw new Error('this type of observerable is not defined for this object');
@arian
arian / EggTimer.js
Created October 28, 2011 15:06
Useful when making pizzas or when you want to be notified when your favorite program on TV starts.
#!/usr/bin/env node
var exec = require('child_process').exec;
var sys = require('sys');
var help = [
'timer.js [OPTIONS]',
'',
'OPTIONS:',
' --time Set expiration time (HH:II)',
// returns the ClickEmitter object (and creates a new ClickEmitter)
// should return an error when the event type does not have a matched
// emitter class (defined by defineEmitter)
var emitter = myElement.on('click');
// Emitter methods: create, add, remove
// returns a Listener object
var listener = emitter.create(function(event){
event instanceof ClickEvent // true
// totally untested and not working code
var Emitter = new Class({
initialize: function(object){
this.object = object;
},
destruct: function(){},
addListener: function(fn){
this.listeners.push(fn);