Skip to content

Instantly share code, notes, and snippets.

View hindenbug's full-sized avatar
💻

Manoj hindenbug

💻
View GitHub Profile
l = "i am what i am"
# to integer
l.unpack('U*') # => [105, 32, 97, 109, 32, 119, 104, 97, 116, 32, 105, 32, 97, 109]
# to hex
l.unpack('H*') # => ["6920616d2077686174206920616d"]
# if you want the hex in array form then
l.unpack('U*').map{|i| i.to_s(16)} # => ["69", "20", "61", "6d", "20", "77", "68", "61", "74", "20", "69", "20", "61", "6d"]
@hindenbug
hindenbug / gist:1096749
Created July 21, 2011 07:48
Using CSV Ruby 1.8 and Ruby 1.9
# in Gemfile
gem "fastercsv", :platforms => [:mri_18, :ruby_18]
# in app/config/environment.rb
require "csv"
unless !CSV.const_defined? :Reader
require "fastercsv"
@hindenbug
hindenbug / gist:1578969
Created January 8, 2012 16:55
ruby-debug with ruby 1.9.3
###In order to use ruby-debug with ruby-1.9.3 you need to download the following from http://rubyforge.org/frs/?group_id=8883 ###
linecache19-0.5.13.gem
ruby_core_source-0.1.5.gem
ruby-debug19-0.11.6.gem
ruby-debug-base19-0.11.26.gem
###then from the terminal run,###
gem install ruby_core_source-0.1.5.gem -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p0
@hindenbug
hindenbug / milestone1.md
Last active December 31, 2015 23:29
Clojure Adventures - MileStone 1
  • Clojure, the core data structures aren't mutable

Clojure Data Structures

Clojure has two types of expressions atoms and collections

ATOMS

Atoms represent Primitive Types in other languages, like:
Numbers, Strings, Boolean, Nil, Symbols, Keywords

;; eg: symbols in clojure, points to a verb or other values
;; when clojure evaluates a symbol it looks up that symbols meaning
inc
;; refer to symbols without evaluating its meaning
;; ' escapes a expression. Quote anything and get it back exactly
;; the same
'inc
@hindenbug
hindenbug / test.clj
Created January 4, 2014 20:33 — forked from adambard/test.clj
; Comments start with semicolons.
; Clojure is written in "forms", which are just
; lists of things inside parentheses, separated by whitespace.
;
; The clojure reader assumes that the first thing is a
; function or macro to call, and the rest are arguments.
;
; Here's a function that sets the current namespace:
(ns test)
@hindenbug
hindenbug / test.clj
Created January 5, 2014 20:24 — forked from adambard/test.clj
; Comments start with semicolons.
; Clojure is written in "forms", which are just
; lists of things inside parentheses, separated by whitespace.
;
; The clojure reader assumes that the first thing is a
; function or macro to call, and the rest are arguments.
;
; Here's a function that sets the current namespace:
(ns test)
; as clojure is built on top of Java, many of its types are old java types
(class 3)
=> java.lang.Long
#Frg Jmp
def solution(x, y, d)
# write your code in Ruby 1.9.3
diff = (y - x)
return 0 if diff.zero?
i = (diff.to_f/d).ceil
return i
end
def solution(a)
# write your code in Ruby 1.9.3
rsum = a.inject(:+)
lsum = 0
res = nil
a.each_with_index do |v, i|
rsum -= v
lsum += v
diff = (lsum - rsum).abs