Skip to content

Instantly share code, notes, and snippets.

View nkpart's full-sized avatar

Nick Partridge nkpart

  • Brisbane, Australia
View GitHub Profile
module Trial where
import System.IO
import System.Directory
import System.Time
fileExists :: FilePath -> IO Bool
fileExists name = do
fileExists <- doesFileExist name
if fileExists
right :: Either a b -> Maybe b
right = either (\a -> Nothing) (\b -> Just b)
-- With more win:
right :: Either a b -> Maybe b
right = either (\a -> mzero) return
module Enumerable
def name_please &blk
inject({}) do |accum, elem|
accum[elem] = blk.call(elem)
accum
end
end
end
[1,2].name_please { |x| "#{x} value" } # <= { 1 => "1 value", 2 => "2 value" }
# http://github.com/evanphx/rubinius/tree/master/lib/actor.rb
# Stripped ends as a `rong` prototype
class Actor
class DeadActorError < RuntimeError
attr_reader :actor
attr_reader :reason
def initialize(actor, reason)
super(reason)
@actor = actor
class Object
def box
self.is_a?(Array) ? self : [self]
end
end
Making RubyMine Pro-er
-----------------------
File->Settings
Editor
[ ] Allow placement of caret after end of line
Editor -> Editor Tabs
[x] Show tabs in single row
Editor -> Appearance
[x] Use antialiased font
sudo gem uninstall nkpart-accidently
sudo gem install nkpart-accidentally
numbers = %w{1.3 1.5 1.8}
puts "# 1 - standard stuff"
p numbers.map { |x| x.to_f }
puts "# 2 - passing in a proc using &"
to_f_proc = proc { |x| x.to_f }
p numbers.map(&to_f_proc)
puts "# 3 - passing in a dynamic proc"
require 'prohax'
def add a
let( :to => proc { |b| b + a })
end
add(5).to(3)
# => 8
def _if s

SORTA-TOSTADA WITH BEANS N SHIT RAWR

  • 1 tomato, chopped into rough chunks
  • Some lettuce, chopped into rough pieces
  • 2 tortillas
  • Half a can of refried beans
  • Half a tub of salsa
  • A bit of grated cheese