Skip to content

Instantly share code, notes, and snippets.

@ifesdjeen
ifesdjeen / Haskell vs Clojure Tail Rec.clj
Last active August 29, 2015 13:56
Comparison of tailrec+pattern matching between Haskell and Clojure
(defn max-from-list
"Get the maximum from list using recursion"
[[head & tail]]
(if (empty? tail)
head
(let [max-in-tail (max-from-list tail)]
(if (> head max-in-tail)
head
max-in-tail))))
(defn almost=
"Non-strict equality"
[wat center tolerance]
(and (>= wat (- center tolerance))
(<= wat (+ center tolerance))))
;; "Normal" operation order
(->> [1 2 3]
(map inc)
(map #(* 2 %)
(reduce +))

First of all, sorry for the messy code (it was in a bad condition, and I've been commenting/uncommenting bunch of things to understand what's going on and where, only got time to fix it but not clearnup)

At first, I've started getting

Stack space overflow: current size 8388608 bytes.
import Control.Concurrent.ParallelIO.Global (parallel)
import Control.Arrow (left)
data DbError = DbError
data Input = Input
data Result = Result
someOperation :: Either DbError [Input]
-> (Input -> IO (Either DbError Result))
-> IO (Either DbError [Result])
(let [channel (create)
incremented-values (map* inc channel)
decremented-values (map* dec channel)]
(consume incremented-values (fn [i] (println "Incremented value: " i)))
(consume decremented-values (fn [i] (println "Decremented value: " i)))
(accept channel 1)
(accept channel 2)
(accept channel 3)
(ms/flush channel))
package introspect;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.AllArguments;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.Origin;
import java.lang.reflect.Method;
public class LogInterceptor {
public static void log(@AllArguments Object[] allArguments,
@Origin Method method) {
@ifesdjeen
ifesdjeen / gist:1058853
Last active September 26, 2015 07:07
Zen and art of motorcycle maintenance quotes
============================================
I have kicked myself mentally a hundred times for that stupidity and don't think I'll ever really, finally get
over it. Evidently what I saw sloshing around was gas in the reserve tank which I had never turned on. I didn't
check it carefully because I assumed the rain had caused the engine failure. I didn't understand then how foolish
quick assumptions like that are. Now we are on a twenty-eight-horse machine and I take the maintenance of it very
seriously.
============================================
I found the cause of the seizures a few weeks later, waiting to happen again. It was a little twenty-five-cent
pin in the internal oil-delivery system that had been sheared and was preventing oil from reaching the head at
high speeds.
@ifesdjeen
ifesdjeen / gist:1240416
Created September 25, 2011 09:26
export your custom dictionary to iknow
# -*- coding: utf-8 -*-
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
Capybara.run_server = false
Capybara.default_driver = :selenium
Capybara.app_host = 'http://iknow.jp'
@ifesdjeen
ifesdjeen / meta.rb
Created May 6, 2012 18:19
metaprogramming magic
module SafeConstDefinition
extend ActiveSupport::Concern
module ClassMethods
def const_missing(name)
puts "Warning: #{name} was not defined, assuming further definition. Keep calm tho."
# Since Parent is defined after Child both in root and in SomeModule,
# i need to have a mechanism to define a future const, but simple: