Skip to content

Instantly share code, notes, and snippets.

@Zirak
Zirak / moo.js
Created March 22, 2012 15:08
cowsay
var moo = (function () {
var cowsay = {
defaults : {
e : 'oo',
T : ' ',
t : false,
W : 40
},
You see the sun setting to your right (it's always to your right.) Beneath
the diminishing globe, the ocean, ending in the horizon; but you know it doesn't
really end. You're driving. Perhaps a car. A convertible? No, maybe a
motorcycle, or just a unicycle. I don't know. You're the one who's driving, you
should know how to do it. Is this a good beginning? To anything? Especially to a
javascript tutorial?
Quentin Tarantino taught me something. Not the singular version of something,
but the plural - he taught me somethings. In one of the greatest movie of all
times (PULP FICTION MOTHERFUCKER HAVE YOU SEEN IT?), Mia Wallace, noticing the
@Zirak
Zirak / gist:3086939
Last active August 27, 2022 22:01
xhr for dummies

So, you want to send a motherfucking XMLHttpRequest (XHR, or commonly and falsly known as AJAX.) Too bad, just ran out of motherfucking XMLHttpRequests; but I still have one regular. XHR is not magic. It does not autofuckinmagically send things the way you want them do be sent. It does not do the thinking for you. It just sends an Http Request.

You get a hold on such a prime beast like this:

@Zirak
Zirak / jhr.js
Created July 20, 2012 15:44
JSONHttpRequest
//this is a tiny helper method for making JSON Http Requests
//if you want a more comprehensive solution, write it yourself
//
//the callback function will receive two arguments: the response,
// parsed as JSON, and the xhr object used inside jhr, with an added
// responseJSON property (you can probably guess what it is)
//
//this always sends a POST request, and the data is always serialized to JSON
//
//returns the xhr object used
@Zirak
Zirak / gist:3351527
Created August 14, 2012 18:34
Shunting Yard
//the Shunting Yard algorithm: turns infix expressions into postfix (RPN)
//supports all but function expressions
//written both for fun, and as an attempt to:
// 1. build a query-less system (only commands)
// 2. follow the "Functions Do Only One Thing" law (or what Uncle Bob calls
// "extract until you drop")
//1 is violated once, in parse.op_weaker; a clever solution will have to be
// found to bypass that hurdle. 2 is violated in parse.parse_op, but as soon as
// I can name that damn while loop, it should be solved.
function shunting_yard ( infix, operators ) {
@Zirak
Zirak / gist:3364309
Created August 15, 2012 22:32
postfix and prefix increment

Postfix increment (i.e. n++) is usually explained as such:

  • Tell me the value of n
  • Increment the value of n

And prefix increment (++n):

  • Increment the value of n
  • Tell me the value of n
@Zirak
Zirak / helloWorld.js
Last active January 21, 2021 18:18
The Hello World of the future
/*
* The Hello World of tomorrow
* Copyright (C) 2012 Scruffy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
#!/bin/bash
#a small script to automate installing from downloaded AUR tarballs
if [ ! -f $1 ]
then
echo "File $1 does not exist" 1>&2
exit
fi
base=$(basename -s '.tar.gz' $1) #meh
@Zirak
Zirak / wireless_install.md
Created November 21, 2012 19:51
don't ever forget these
Display block devices list:
$ lsblk
Mounting a user-writable fs:
# mount -o gid=users,fmask=113,dmask=002 /dev/sdx path
@Zirak
Zirak / fragger.js
Created December 6, 2012 15:20
util for text search/replace for DOM output
var fragger = {
root : null,
cur_root : null, //ungh, but I can't find a better place...
last_index : null,
new : function () {
return Object.create( this );
},
init : function ( text ) {