Skip to content

Instantly share code, notes, and snippets.

@adomokos
adomokos / bubble_sort.rb
Created January 24, 2013 18:21
Bubble Sorting in Ruby
module Enumerable
def bubble_sortit
reached_end = true
(1..self.length-1).each do |e|
if self[e] < self[e-1]
self[e-1], self[e] = self[e], self[e-1]
reached_end = false
end
end
@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]))))
(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 / string_calculator.hs
Created July 14, 2016 17:44
String Calculator in Haskell
module StringCalculator where
import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)
import Data.List.Split (splitOn)
calculator' :: String -> Char -> Integer
calculator' x c = sum $ coerceString x c
@adomokos
adomokos / string_calculator_test.go
Created January 5, 2017 03:42
String Calculator in Go
package string_calculator
import (
"github.com/stretchr/testify/assert"
"strconv"
"strings"
"testing"
)
func Convert(params ...string) int {
@adomokos
adomokos / RomanNumeralsSpec.hs
Created April 26, 2017 04:42
The Roman Numerals kata in Haskell
import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)
import qualified Data.Map as Map
import Data.List
mapping :: Map.Map Int String
mapping = Map.fromList [
(1, "I"),
(4, "IV"),