Skip to content

Instantly share code, notes, and snippets.

View marcosccm's full-sized avatar

Marcos Castilho da Costa Matos marcosccm

View GitHub Profile

Immortal Ruby

  • Desired talk duration: 30 minutes

Abstract

Should rubyists care about immutability? Yes! On this talk we discuss why immutability is an important concept and the many ways you can apply it to your Ruby Projects, from using specific gems to having immutability as a design tool. Let's not let the functional languages steal all the fun!

@marcosccm
marcosccm / silly.rb
Last active January 3, 2016 11:19
get samples from an array n times and see each element appears more times
10.times.collect { ["clj", "blog", "pacto"].sample }.group_by { |x| x }.map { |k,v| [k,v.size] }.max_by { |x| x.last }
10.times.collect { ["clj", "blog", "pacto"].sample }.inject(Hash.new(0)) { |acc, elem| acc[elem] += 1; acc }.max_by { |k,v| v }
@marcosccm
marcosccm / server.rb
Last active December 21, 2015 03:58
WEBrick dummy server
require 'webrick'
json = File.read("./file.json")
class Server < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, json)
super(server)
@json = json
end
def do_GET(request, response)
response.status = 200
@marcosccm
marcosccm / robot.js
Created December 8, 2012 13:14
Mammoth
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
var lockLevel = 0;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if(this.lockLevel > 0){
@marcosccm
marcosccm / robot.js
Created December 8, 2012 12:37 — forked from kjaku/robot.js
Bubu
var Robot = function(robot) {
// var robot = ev.robot;
}
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.clone();
robot.rotateCannon(360);
robot.turn(360)
@marcosccm
marcosccm / robot.js
Created December 8, 2012 12:36
Zolmeister
var robots = new Array();
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.start = function( ev ){
@marcosccm
marcosccm / gist:2930789
Created June 14, 2012 14:48
WCC 2012.24
import Data.List
import Data.Function
wcc = maximumBy (compare `on` sum) . filter (not . null) . concatMap inits . tails
@marcosccm
marcosccm / gist:2845491
Created May 31, 2012 19:06
wcc 2012.22
import Data.List
import Data.Function
wcc :: (Ord a, Num a) => a -> [a] -> [[a]]
wcc x = maximumBy (greaterSum) . groupBy (sameSum) . filter (sumSmallerThenTarget) . subsequences . filter (< x) . sort
where sumSmallerThenTarget xs = (sum xs) < x
sameSum a b = sum a == sum b
greaterSum = compare `on` (sum . concat)