Skip to content

Instantly share code, notes, and snippets.

@solomon081
solomon081 / isort.fs
Created August 15, 2012 19:48
Insertion Sort F#
let insert (a: array<int>) i item =
let mutable i = i - 1
while i >= 0 && item < a.[i] do
a.[i + 1] <- a.[i]
i <- i - 1
a.[i + 1] <- item
let isort (a: array<int>) =
let a = Array.copy a
for i in 1 .. (a.Length - 1) do
@solomon081
solomon081 / experiments.hs
Created July 19, 2012 02:58
Haskell Experiments
ordered :: Int -> Int -> (Int, Int)
ordered x y
| x >= y = (x, y)
| otherwise = (y, x)
sumAndProduct :: Int -> Int -> (Int, Int)
sumAndProduct x y = (x + y, x * y)
shift :: ((Int, Int), Int) -> (Int, (Int, Int))
shift ((x, y), z) = (x, (y, z))
@solomon081
solomon081 / HistoryContainer.cpp
Created July 4, 2012 17:43
bashcmd Interpreter
#include "stdafx.h"
#include "HistoryContainer.h"
using namespace std;
void HistoryContainer::AddItem(string item)
{
history.push_back(item);
}
#include "stdafx.h"
#include <iostream>
#include <string>
#include <regex>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
using namespace std;
#include "stdafx.h"
#include <iostream>
#include <string>
#include <regex>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
using namespace std;
// rankclass.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Ranker
{
function tmpl(template, arr) {
if (template.constructor !== String) {
throw "Template must be a string!";
}
for (var i = 0; i < arr.length; i++) {
template = template.replace("%{" + i + "}%", arr[i]);
}
return $(template)[0];
}
function getScript(url) {
var xml = new XMLHttpRequest();
xml.onreadystatechange = function () {
if (xml.readyState === 4 && xml.status === 200) {
eval(xml.responseText);
console.log("Evaluated the Javascript.");
}
}
xml.open("GET", url, true);
xml.send();
@solomon081
solomon081 / Use
Created June 19, 2012 18:50
ClassLib
>>> User = new Class();
>>> User.addInstanceFunc("isUser", function(){console.log("Yeppers!")})
>>> userOne = new User();
>>> userOne.isUser();
Yeppers!
>>> User.addClassFunc("allUsers", function(){console.log("Just that guy...")})
>>> User.allUsers();
Just that guy...
>>> Parent = new Class();
>>> Parent.addInstanceFunc("noActualUse",function(){console.log("This has no use!")});
@solomon081
solomon081 / searchinelements.js
Created June 17, 2012 00:34
searchInElements
/**
* @author Solomon Wise
*/
"use strict";
var domTools = {};
domTools.searchInElements = function (elem, pattern) {
if (pattern.constructor !== RegExp) {
throw "Pattern must be a RegExp";
}
if (elem.constructor !== String) {