Skip to content

Instantly share code, notes, and snippets.

View robertsosinski's full-sized avatar

Robert Sosinski robertsosinski

View GitHub Profile
@robertsosinski
robertsosinski / Factorial.scala
Created April 7, 2014 05:37
Generating factorial numbers with parallel processing using Akka
import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
object Factorial extends App {
val factorials = List(200000, 180000, 320000, 280000, 220000, 420000, 550000, 480000)
val system = ActorSystem("factorial")
val collector = system.actorOf(Props(new FactorialCollector(factorials)), "fac-coll")
system.awaitTermination()
@robertsosinski
robertsosinski / .jshintrc
Last active August 29, 2015 14:00
My JSHint Options
{
"browser": true, // specifies globals exposed by modern browsers
"strict": true, // specifies that restricted JavaScript is used
"indent": 2, // indentation should consistently be 2 spaces
"nonew": true, // prevents using constructers for side effects
"noarg": true, // prevents using deprecated caller,callee methods
"eqeqeq": true, // prevents equality == and != operators from being used
"bitwise": true, // prevents bitwise & and | operators from being used
@robertsosinski
robertsosinski / factorial.go
Last active August 29, 2015 14:01
Computing Factorials in Parallel in Go
package main
import (
"fmt"
"math/big"
"runtime"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
@robertsosinski
robertsosinski / application.rb
Created April 6, 2009 14:53
A simple way to manage multiple parameters in Rails routing
before_filter :hash_options
def hash_options
params[:options] = Hash[*((params[:options].size % 2) == 0) ? params[:options] : (params[:options] + [nil])] if params[:options]
end
@robertsosinski
robertsosinski / Event.simulate.js
Created April 11, 2009 21:32
Fire native events: Taken from kangax/protolicious
(function(){
var eventMatchers = {
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
'MouseEvents': /^(?:click|mouse(?:down|up|over|move|out))$/
}
var defaultOptions = {
pointerX: 0,
pointerY: 0,
button: 0,
ctrlKey: false,
@robertsosinski
robertsosinski / tmp.rake
Created April 19, 2009 03:38
Deletes js and css cache files: Taken from maintainable software
namespace :tmp do
namespace :assets do
desc "Clears javascripts/cache and stylesheets/cache"
task :clear => :environment do
FileUtils.rm(Dir['public/javascripts/cache/[^.]*'])
FileUtils.rm(Dir['public/stylesheets/cache/[^.]*'])
end
end
end
@robertsosinski
robertsosinski / gist:98576
Created April 20, 2009 15:14
Understanding how to bind scope in JavaScript
window.scope = "window";
Function.prototype.bind = function(scope) {
var _function = this;
return function() {
return _function.apply(scope, arguments);
}
}
@robertsosinski
robertsosinski / scope.js
Created April 27, 2009 16:29
Understanding how to bind scope in JavaScript with constructors
Function.prototype.bind = function(scope) {
_function = this;
return function() {
_function.apply(scope, arguments);
}
}
window.scope = "window";
@robertsosinski
robertsosinski / gist:123078
Created June 3, 2009 16:32
Converts a query string to a Prototype.js Hash
Hash.fromQueryString = function(string) {
var hash = new Hash();
var array = string.gsub(/^#/, '').split(/=|&/);
for (var i = 0; i < array.length; i+=2) {
if(array[i +1] != undefined) {
hash.set(array[i], array[i + 1]);
}
}
@robertsosinski
robertsosinski / gist:192975
Created September 24, 2009 19:39
RegEx scrubber to make permalinks from strings
name.downcase.gsub(/'/, "").gsub(/[^[:alnum:]]/, "_").gsub(/_{2,}/, "_").gsub(/^_|_$/, "")
# scrub out: ^contractions ^non-alpha-num characters ^extra underscores ^other underscores