Skip to content

Instantly share code, notes, and snippets.

@cronin101
cronin101 / fizzbuzztination.rb
Created July 20, 2012 12:18
Fizzbuzztination
1.9.3p194 :001 > range = (1..20)
=> 1..20
1.9.3p194 :002 > fizz = ->(x){ "fizz" if x.modulo(3).zero? }
=> #<Proc:0x007febfc141140@(irb):2 (lambda)>
1.9.3p194 :003 > buzz = ->(x){ "buzz" if x.modulo(5).zero? }
=> #<Proc:0x007febfc137938@(irb):3 (lambda)>
1.9.3p194 :004 > fizz_list = range.map(&fizz)
@cronin101
cronin101 / wenmedals.rb
Created August 7, 2012 14:20
This is how many times Wen is allowed to celebrate before she dies.
1.9.3p194 :001 > SINGAPOREAN_FEMALE_LIFE_EXPECTANCY = 83 #http://en.wikipedia.org/wiki/List_of_countries_by_life_expectancy
=> 83
1.9.3p194 :002 > AGE_OF_WEN = 22
=> 22
1.9.3p194 :003 > years = (2012..2012+(SINGAPOREAN_FEMALE_LIFE_EXPECTANCY - AGE_OF_WEN))
=> 2012..2073
1.9.3p194 :004 > oly_years = years.find_all { |y| y.modulo(4).zero? }
@cronin101
cronin101 / middleman_idea.rb
Created August 14, 2012 09:14
An idea for the DSL for translating between object representations of data from online tools
from :youtrack_issue do |issue|
# $ ki_youtrack issue KI-1 | ki_middleman --to pivotal_story | ki_pivotal story --project 500123
to :pivotal_story do
{
:name => "[#{issue.id}] #{issue.summary}",
:description => "#{issue.description}"
}
end
# Example of something else that might use an issue
@cronin101
cronin101 / .profile
Created September 3, 2012 10:24
Script that takes id from current branch (for prepending commits) and addition to ~/.profile for aliasing
alias story="~/dev/storyid.rb"
@cronin101
cronin101 / because_why_not.rb
Created September 5, 2012 22:37
Ruby makes your code so concise and understandable! It is self documenting!
#!/usr/bin/ruby
virgin_isp,isp= \
[->(is_best,isp){is_best.unshift \
isp},\
who_is_best=[virgin_isp]]
(best = [[[-1]\
[-1]]\
[-1]][((-1))])
VIRGIN=<<isp
ZWQgdG8gYmUgYSBkaWNrLicgfS5qb2lu\n
@cronin101
cronin101 / HaDope.rb
Last active December 11, 2015 04:38
HaDope syntax idea
gpu = HaDope::GPU.new
dataset = HaDope::Dataset.new {
type: :int,
size: 100,
data: (1..100).to_a
}
gpu.load(dataset)
@cronin101
cronin101 / gpu_spec.rb
Last active December 11, 2015 09:39
RSpec your GPU today.
require 'spec_helper'
describe HaDope::GPU do
before(:all) do
@input_array = (1..10000000).to_a
HaDope::DataSet.create({ name: :test_dataset, type: :int,
data: @input_array })
HaDope::Map.create({ name: :test_task, key: [:int, :i],
function: 'i++;' })
@cronin101
cronin101 / toy.c
Last active December 12, 2015 01:29
Printing 1 to N in C without loops, conditionals or segfaults.
#include <stdio.h>
#include <stdlib.h>
void (**functions);
void executeFunction(void(*f)()){
f();
}
void executeFunctionAt(const int index){
@cronin101
cronin101 / pokemon_hax.rb
Last active December 15, 2015 14:49
Cheating at pokemon battles.
#!/usr/bin/env ruby
require 'httparty'
require 'nokogiri'
def info_page_html_for(pokemon)
reponse = HTTParty.get "http://bulbapedia.bulbagarden.net/wiki/#{pokemon}_(Pok%C3%A9mon)".force_encoding('UTF-8')
end
def weakness_table_for(pokemon)
@cronin101
cronin101 / comn.md
Last active December 16, 2015 12:19
COMN Revision Notes

#Computer Networks

Location: St. Leonard's Land Gym 4

Date/Time: Monday 29/04/2013, 09:30:00-11:30:00 (02:00:00)

Examinable Material

?

COMN Required Readings