Skip to content

Instantly share code, notes, and snippets.

@adomokos
adomokos / loads_position_types.rb
Created February 21, 2013 22:59
DRY-ing up service logic with mixins. Since these services are very similar in behavior I used a "template" method that uses only one dynamic data: the entity type they are fetching.
module Services
class LoadsPositionTypes
extend ::Services::LookupDataFetchable
def self.entity_class
PositionType
end
end
end
@adomokos
adomokos / vim_katas_01.md
Last active December 18, 2015 05:48
vim katas

Selection

  1. type in the word: "errors for job profile"
  2. move to the first 'p'
  3. select the entire content within the quotes: vi"
  4. select just from the cursor to the quotes: vt"
  5. delete just from the cursor location to the quote: dt"
  6. delete everything within the quotes: di"

Creating, using marks

  1. open a file with a few hundred lines of code
@adomokos
adomokos / vim_katas_02.md
Last active December 18, 2015 09:59
vim katas

The Yank Register

  1. Start at the first character of the first line collection = getCollection(); process(somethingInTheWay, target);
  2. Yank the word "collection" with - yiw
  3. Move to the beginning of the word "somethingInTheWay" with - jww
  4. Delete the word "somethingInTheWay" with - diw
  5. Paste from the Yank Register with - "0P
  6. Look at the Yank Register with - :reg "0
@adomokos
adomokos / fizzbuzz.clj
Last active January 1, 2016 11:48
Solving the "FizzBuzz" kata (http://codingdojo.org/cgi-bin/wiki.pl?KataFizzBuzz) in Clojure
(ns fizzbuzz.core
(:gen-class))
(defn- format-output [output current]
(cond
(= 0 (mod current 15)) (str output "FizzBuzz\n")
(= 0 (mod current 3)) (str output "Fizz\n")
(= 0 (mod current 5)) (str output "Buzz\n")
:else (str output current "\n")))
@adomokos
adomokos / keyword_like_function_test.clj
Created January 6, 2014 14:40
An example to create keyword-like arguments for a Clojure function
(ns keyword-like-function-test
(:require [clojure.test :refer :all]))
(defn find-values
[& {:keys [p1 p2] :or {p1 [0 0] p2 [1 1]}}]
[p1 p2])
(deftest keyword-arguments-test
(testing "when both of the arguments were passed"
(is (= [4 15] (first (find-values :p1 [4 15] :p2 [3 21]))))
@adomokos
adomokos / group_by_spec.rb
Created March 5, 2014 04:12
Recognizing Ruby's group_by in the imperative code
class Location
attr_reader :city, :user
def initialize(city, user)
@city = city
@user = user
end
end
class User
attr_reader :name
@adomokos
adomokos / string_calculator_spec.rb
Last active August 29, 2015 14:12
String Calculator Kata in Ruby - using enumerable methods
# Solving the String Calculator Kata
# http://osherove.com/tdd-kata-1/
class StringCalculator
def self.add(numbers)
return 0 if numbers.empty?
numbers.split(",").map(&:to_i).reduce(:+)
#splitted_array = numbers.split(",")
@adomokos
adomokos / core_test.clj
Created May 15, 2015 18:53
Solving the Roman Numeral Kata in Clojure
(ns roman-numerals.core-test
(:require [clojure.test :refer :all]))
(def mapping {
0 ""
1 "I"
4 "IV"
5 "V"
9 "IX"
10 "X"
(ns change-maker.core-test
(:require [clojure.test :refer :all]))
(def ^:dynamic *denominations* [25 10 5 1])
(defn best-match [value]
(first (filter #(<= % value) *denominations*)))
(defn calculate-change [value product]
(let [reducer (best-match value)]
@adomokos
adomokos / Makefile
Last active February 18, 2020 00:21
Makefile template
DBUSER=db_user
DBPASSWD=db_password
DBNAME=some_db
THIS_FILE := $(lastword $(MAKEFILE_LIST))
.DEFAULT_GOAL := help
build-db: ## Builds the DB
dropdb --if-exists --username $(DBUSER) $(DBNAME)