Skip to content

Instantly share code, notes, and snippets.

@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:
@ifesdjeen
ifesdjeen / initscript.sh
Created May 12, 2012 17:32
Capistrano deployment
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/a/my-app/current/run.sh
PIDDIR=/a/my-app/current/tmp/pids
PIDFILE="$PIDDIR/my-app.pid"
USER="myuser"
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
@ifesdjeen
ifesdjeen / wrap_fn.clj
Created May 22, 2012 11:36
Wrapping functions in Clojure
(defn wrap-fn
"Wrap or replace some function with your own function"
[qualifier wrapper]
(alter-var-root
qualifier
(fn [original-fn]
(fn [& caller-arguments]
(wrapper caller-arguments original-fn)))))
;; Replace your function implementation:
@ifesdjeen
ifesdjeen / persistent-ssh-tunnel.sh
Created June 14, 2012 21:08
Persistent SSH Tunnel
HOST = # masked
SOURCE_PORT = 5672
DESTINATION_PORT = 5672
USERNAME = ifesdjeen
createTunnel() {
/usr/bin/ssh -f -N -L$SOURCE_PORT:$HOST:$DESTINATION_PORT -L19922:HOST:22 ifesdjeen@$HOST
if [[ $? -eq 0 ]]; then
echo Tunnel to $HOST created successfully
else
@ifesdjeen
ifesdjeen / global_catch_exception.clj
Created June 26, 2012 14:47
Global Exception catching
;; That will actually catch exception within inner thread, too. And within inner thread of inner thread. Etc.
(Thread/setDefaultUncaughtExceptionHandler (proxy [Thread$UncaughtExceptionHandler] []
(uncaughtException [t e]
;;
;; Your fancy Exception logging here
;;
(println "Throwable: " + (.getMessage e))
(println (.toString t)))))
(.start (Thread. (cast Runnable
(fn []
@ifesdjeen
ifesdjeen / get_in.rb
Created August 14, 2012 09:21
Clojure get_in in ruby
# Returns value from hash based on the path
#
# @param hash [Hash] - hash to retrieve values from
# @param path [Array] - non-empty array representing recursive path
#
# @returns [Object] - an object located within an array on the given path
#
# Examples:
#
# get_in({:a => {:b => {:c => 2}}}, [:a, :b, :c]) # => 2
(ns clojurewerkz.cassaforte.thrift.column
(:use [clojurewerkz.support.string :only [to-byte-buffer]]
[clojurewerkz.cassaforte.bytes :only [encode]])
(:import [org.apache.cassandra.thrift Column]))
(defn ^Column build-column
"Converts clojure map to column"
([^String key ^String value]
(build-column to-byte-buffer key value (System/currentTimeMillis)))
@ifesdjeen
ifesdjeen / shunting_yard.clj
Created November 25, 2012 19:35
Check wether it's easier or harder to read the code that way
;;
;; Leaving defaccumulator/defcompound details aside, when you see following lines, is it clear what's going on?
;; Or is it easier to read a straightforward loop, without dispatcher-based magic?
;;
;; As for me, advantage is that rules are completely decouple from each other. It's very easy to understand and
;; debug parts of the processing, rather than try to figure out how the complete algorithm works at once.
;; When reading algorithm description, you see clear definition of steps and rules, although when you see
;; the implementation it's all combined into one humongous function, that's doing everything, and dispatch rules
;; are wowed, which makes it even more complex.
;;