Skip to content

Instantly share code, notes, and snippets.

# Simple class which encapsulates Fizz Buzz logic. I decided to leave :fizz? and :buzz? method
# public, but in case of this puzzle it is unnecessary.
class FizzBuzz
FIZZ = "Fizz"
BUZZ = "Buzz"
def initialize(number)
@number = number
end
irb(main):002:0> @assign = {}
=> {}
irb(main):003:0> @assign[2] = 20
=> 20
irb(main):004:0> @assign[5] = 50
=> 50
irb(main):005:0> @assign[4] = 40
=> 40
irb(main):006:0> @assign[3] = 30
=> 30
public class Riddle {
public static void main( String[] args ){
String[] nbrs = "67 64 5b 59 5g 57 60 5f 67 68 57 1e 3b 48 41 1e 29 1e 67 68 57 66 67 6e 6d 1e 64 66 63 5d 66 57 61 5f 67 68 57 1e 48 40 48".split(" ");
for( String nbr : nbrs ){
System.out.print( (char)Integer.parseInt(nbr, 18 ) );
}
}
}
# -*- coding: utf-8 -*-
# Zmiany w klasie String:
# * downcase - standardowa implementacja nie działa na JRuby
# * upcase - standardowa implementacja nie działa na JRuby
class String
alias_method :old_downcase, :downcase
def downcase
if self == old_downcase
new_downcase
@seban
seban / gist:3238879
Created August 2, 2012 17:19
tmx configuration
set-window-option -g automatic-rename on
set-window-option -g mode-keys vi
bind l select-pane -R
bind k select-pane -U
bind j select-pane -D
bind h select-pane -L
set -g status off
set -g default-terminal "screen-256color"
set-window-option -g utf8 on # utf8 support
# new-session
class OfferItem
attr_reader :name, :price
def initialize(name, price)
@name = name
@price = price.to_f
end
def ==(obj)
source "http://rubygems.org"
source "http://gems.ruby-lang.org"
gem "ruby-net"
gem "ruby-csv"
(defproject example "0.1"
:description "My simple Clojure examples"
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/math.numeric-tower "0.0.1"]]
:main example.core)
@seban
seban / gist:2043519
Created March 15, 2012 10:31
JSON with unicode chars doesn't work?
# encoding: utf-8
require 'rubygems'
require 'json'
attributes = { "join_id" => "12345678901234567890", "description" => "źle" }
jsoned = JSON.fast_generate(attributes)
puts jsoned.encoding
require 'rubygems'
require 'active_support'
require 'active_support/core_ext/hash/indifferent_access'
require 'benchmark'
ALPHA = ('a'..'z').to_a
simple_hash = ALPHA.inject({}) { |hash, element| hash[element] = element ; hash }
indifferent_hash = ALPHA.inject(HashWithIndifferentAccess.new) { |hash, element| hash[element] = element ; hash }
Benchmark.bm do |x|