Skip to content

Instantly share code, notes, and snippets.

View migimunz's full-sized avatar

Nemanja Stojanovic migimunz

View GitHub Profile
@migimunz
migimunz / example1.hs
Created February 19, 2018 21:22
CS162 - haskell examples
import Prelude hiding (foldl)
data Moody a = Happy a | Depressed a
deriving Show
foo (Happy a) = Happy (a + 1)
foo (Depressed a) = Depressed (a - 1)
foldl :: (b -> a -> b) -> b -> [a] -> b
### Redirects controller:
class RedirectsController < ApplicationController
def create
redirect_to "http://www.google.com"
end
end
### Routes
@migimunz
migimunz / format.js
Last active August 29, 2015 14:22
A quick and dirty C#-like format function for js.
var format = function() {
var args = Array.prototype.slice.call(arguments);
var fmt = args[0];
var vals = args.slice(1);
return fmt.replace(/(?:^|([^{]))\{(\d+)\}/g, function(_, pref, i) {
pref = pref || '';
return pref + vals[i];
}).replace(/{{|}}/g, function(s) {
return s[0];
});
@migimunz
migimunz / gist:bef02ed174c42e2080c3
Created May 15, 2015 13:40
A small sinatra app that just prints the request details it gets. Useful for debugging clients and reverse proxies.
require 'sinatra/base'
require 'pp'
class HttpDebug < Sinatra::Base
set :port, ARGV[0] || 8001
set :logging, false
[:get, :put, :post, :patch, :delete, :head, :link, :unlink, :options].each do |method|
send(method, '*') do
function f(x) {
return Math.round(1 / (0.5 * Math.sqrt(Math.PI)) * Math.pow(Math.E, (-Math.pow(x%3, 2)/Math.pow(0.1,2)))
+ 1 / (0.27 * Math.sqrt(Math.PI)) * Math.pow(Math.E, (-Math.pow(x%5, 2)/Math.pow(0.1,2))));
}
var text = ["%", "Fizz", "Buzz", "FizzBuzz"];
for(var x = 1; x <= 100; ++x) {
console.log(text[f(x)].replace('%', x));
}
@migimunz
migimunz / gist:3eb99184fb9d3b8ac5a1
Created September 13, 2014 00:38
Solving fizzbuzz with genetic algorithms - somewhat correct!
# The best result I got so far is 72.9% , which is
# close enough for most real word uses.
Defs = {
fizz: 0,
buzz: 1,
fizzbuzz: 2,
neither: 3
}
@migimunz
migimunz / gist:61557b7fab233604ba46
Created May 30, 2014 17:58
jQuery query param serialization with dot notation support
var r20 = /%20/g,
rbracket = /\[\]$/,
rCRLF = /\r?\n/g,
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
rsubmittable = /^(?:input|select|textarea|keygen)/i,
rIdentifier = /^[$A-Z_][0-9A-Z_$]*$/i;
jQuery.fn.extend({
serialize: function() {
return jQuery.param( this.serializeArray() );
@migimunz
migimunz / gist:3250590
Created August 3, 2012 19:19
the int problem
/* ... */
class TilemapIterator
{
private var tilemap:FlxTilemap;
private var curX:Int;
private var curY:Int;
private var endX:Int;
private var endY:Int;
public function new(tilemap:FlxTilemap, x1:Int, y1:Int, x2:Int, y2:Int)
@migimunz
migimunz / pad.js
Created June 3, 2011 23:20
Pad numbers with leading zeros
//for that guy on #javascript
function paddedNumber(n, places)
{
var strn = n.toString();
var zerosToAdd = places-strn.length;
if(places !== undefined && zerosToAdd > 0)
while(zerosToAdd--)
strn = "0"+strn;
return strn;
}
@migimunz
migimunz / partial.js
Created May 22, 2011 20:07
Javascript partial application
function swap(f)
{
return function(a, b)
{
return f(b, a);
};
}
function ArgPos(i)