Skip to content

Instantly share code, notes, and snippets.

View ravicious's full-sized avatar

Maja Cieślak ravicious

View GitHub Profile
$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Prelude> :t foldl
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
$ elm repl
---- elm-repl 0.17.1 -----------------------------------------------------------
:help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> List.foldl
@ravicious
ravicious / reproduction.rb
Created August 18, 2016 17:55
Reproduction of the issue with using the `primitive` method within the custom attribute class body.
# ruby reproduction.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
type alias TimesClicked = Int
type alias Count = Int
updateCount : Msg -> TimesClicked -> TimesClicked
updateCount msg count =
case msg of
Increment ->
if count < maxCount then count + 1 else count
Decrement ->
@ravicious
ravicious / keybase.md
Created October 4, 2015 12:02
Keybase.io verification

Keybase proof

I hereby claim:

  • I am ravicious on github.
  • I am ravicious (https://keybase.io/ravicious) on keybase.
  • I have a public key whose fingerprint is 0521 7C74 347E 6D6B 7882 728B FF5B 4F7D 53F3 19D9

To claim this, I am signing this object:

threads = concurrency_level.times.map { |i|
-> {
Thread.new do
begin
customers[i].buy_products([{quantity: 1, product: product}])
rescue Orders::CreateOrderService::Invalid
fail_occurred = true
end
end
}
@ravicious
ravicious / private_function.js
Created June 4, 2015 18:33
Private function example based on raganwald's "Classes are Expressions" http://raganwald.com/2015/06/04/classes-are-expressions.html Discussion: https://news.ycombinator.com/item?id=9660908
let Person = (() = > {
let firstNameProperty = Symbol('firstName'),
lastNameProperty = Symbol('lastName'),
renameProperty = Symbol('rename');
let rename = function(first, last) {
this[firstNameProperty] = first;
this[lastNameProperty] = last;
return this;
}
@ravicious
ravicious / hash_bench.rb
Created April 6, 2015 08:29
Hash[] vs Array#to_h
require 'benchmark/ips'
DEFAULT_CHARSET = ('a'..'z').to_a + (0..9).to_a
def random_symbol
charset = ('a'..'z')
random_string(charset).to_sym
end
def random_string(charset = DEFAULT_CHARSET)
; different approaches to constructing handlers in re-frame
; which one's better?
(register-handler
:cell-clicked
(fn [db _]
(dispatch [:change-cell-owner])
(dispatch [:change-current-player])))
(register-handler
@ravicious
ravicious / parens.md
Last active August 29, 2015 14:17
Real talk about dem brackets

Real talk about dem brackets

  • Steve Losh's great post A Modern Space Cadet.
    • Shift Parentheses section.
      • You might want to skip the last <autogen> rule, as it makes typing uppercased words by holding the shift key a pretty terrible experience.
    • Control/Escape section.
    • KeyRemap4MacBook is now Karabiner.
  • Using Linux? You can get pretty much the same results with xmodmap, just google around.
  • Shif parentheses can be done in a similar way, I'll post my xmodmap config for them when I get home.
@ravicious
ravicious / example_a.rb
Created January 13, 2015 21:06
Code examples for my comment under Henrik's post http://thepugautomatic.com/2015/01/exception-class/
begin
class_a_instance.do_something
class_b_instance.do_something
rescue A::NotEnoughMoney
log_error
cleanup
rescue B::NotEnoughMoney
just_send_email
end