Skip to content

Instantly share code, notes, and snippets.

#putc - put one character to output (interrupt 11)
putc $1 addi $2,$0,11 addu $4,$0,RG1 syscall
#getc - get one character (interrupt 12)
getc $1 addi $2,$0,12 syscall add RG1, $0, $2
#puts - put a string (interrupt 4)
puts $1 addi $2,$0,4 addu $4,$0,RG1 syscall
#done - end the program (interrupt 10)
# send libnotify updates only for certain users. Edit the variable okAccounts to select which accounts.
#
# depends on notify-send
# To install, add this to your ~/.purple/plugins directory (you may have to create it)
# Then enable the plugin
use Purple;
# edit the keys in this hash to enable alerts for only these users
# the value is irrelevant
%okAccounts = ('User 1' => '1',
@Xodarap
Xodarap / SpecialWordsTokenFilter.cs
Created January 14, 2011 16:21
Tokenizes some two-word phrases as a single word
/// <summary>
/// Normally, we tokenize based on white space. But there are times we want to keep words across whitespace, e.g.
/// "in basket" should not become "in" "basket". This class allows you to do that.
/// </summary>
class SpecialWordsTokenFilter : TokenFilter
{
// TODO: Set position and offset attributes as well as term
readonly TermAttribute termAttribute;
readonly Dictionary<string, string> TwoWords = new Dictionary<string, string>();
private Queue<string> bufferBuffer = new Queue<string>();
@Xodarap
Xodarap / booth.py
Created May 14, 2011 00:21
Booth's Multiplication Algorithm
from bitstring import BitArray
'''
Returns m * r using Booth's algorithm.
x = len(m) and y = len(r). Note that this is the length in base 2.
See http://en.wikipedia.org/wiki/Booth%27s_algorithm
'''
def booth(m, r, x, y):
# Initialize
totalLength = x + y + 1
@Xodarap
Xodarap / toggleAttr.js
Created May 21, 2011 14:40
jQuery toggle attribute
(function ($) {
$.fn.toggleAttr = function (attr, val1, val2) {
///<summary>Toggles an attribute between having one of two possible states</summary>
///<param name="attr">Attribute name</param>
///<param name="val1">First value</param>
///<param name="val2">Second value</param>
return this.each(function () {
var $this = $(this);
if ($this.attr(attr) === val1) {
@Xodarap
Xodarap / yc.hs
Created May 25, 2011 00:59
Haskell Y Combinator
-- | Y combinator. Note that this doesn't actually compile in Haskell, but it's simpler
-- than the one which works
Y f = (\x -> f (x x)) (\x -> f (x x))
@Xodarap
Xodarap / yce.hs
Created May 25, 2011 01:01
YC example
-- An example of how the Y combinator expands into an infinite
-- list of function applications
Y f = (\x -> f (x x)) (\x -> f (x x))
= f $ (\x -> f (x x)) (\x -> f $ x x)
= f $ f $ (\x -> f $ x x) (\x -> f $ x x)
= f $ f $ f $ (\x -> f $ x x) (\x -> f $ x x)
= f $ f $ f $ f $ (\x -> f $ x x) (\x -> f $ x x)
@Xodarap
Xodarap / fyc.hs
Created May 25, 2011 01:04
Fake YC application
-- | Mu is just a wrapper since we can't create infinitely recursive type
-- signatures for functions, but we can create recursive ADTs.
-- You can glean the point of Mu from the type signature of actualFn
data Mu a = Mu { actualFn :: [Mu a] -> a -> a }
-- | Factorial function
fact :: Num a => [Mu a] -- ^ An infinite list of factorial functions
-> a -- ^ The number to find the factorial of
-> a
fact (f:fs) n = if n == 1 then 1
@Xodarap
Xodarap / iyca.hs
Created May 25, 2011 01:06
Infinite YC application
fact genFact n = if n == 1 then 1
else n * (
if (n-1) == 1 then 1
else (n-1) * (
if (n-2) == 1 then 1
else (n-2) * (
if (n-3) == 1 then 1
else (n-3) * (
...
)
@Xodarap
Xodarap / SpecialWordsTokenFilter.cs
Created September 30, 2011 14:38
Multiple words which should be tokenized as one word
/// <summary>
/// Normally, we tokenize based on white space. But there are times we want to keep words across whitespace, e.g.
/// "in basket" should not become "in" "basket". This class allows you to do that.
/// </summary>
class SpecialWordsTokenFilter : TokenFilter
{
readonly TermAttribute termAttribute;
readonly Dictionary<string, string> TwoWords = new Dictionary<string, string>();
private Queue<string> bufferBuffer = new Queue<string>();