Skip to content

Instantly share code, notes, and snippets.

@nelanka
nelanka / gitsquash
Last active August 29, 2015 14:05
Git Recipe - Squash a bunch of commits down
# Reset the current branch to the commit just before the last 12:
git reset --hard HEAD~12
# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
git merge --squash HEAD@{1}
# Commit those squashed changes. The commit message will be helpfully
# prepopulated with the commit messages of all the squashed commits:
@nelanka
nelanka / gitrevert
Created September 15, 2014 15:00
Git Recipe - Revert Several Commits
# http://stackoverflow.com/questions/1463340/revert-multiple-git-commits
# A <-- B <-- C <-- D <-- master <-- HEA
git revert --no-commit D
git revert --no-commit C
git revert --no-commit B
git commit -m'the commit message'
@nelanka
nelanka / magic.scala
Created September 25, 2014 19:40
MA Magic
Goal: To understand what this does:
mapChargesOverrides(iChargeOverrides).map(validateCharge).sequence[PartialApply1Of2[ValidationNEL, String]#Apply, Charge]
Lets look at the types leading up to the sequence operation:
mapChargesOverrides(iChargeOverrides) : Seq[Charge]
mapChargesOverrides(iChargeOverrides).map(validateCharge) : Seq[ValidationNEL[String, Charge]]
We can decompose using the type alias:
type ValidationNEL[E, X] = Validation[NonEmptyList[E], X]
@nelanka
nelanka / mapmerge.scala
Created September 30, 2014 18:49
Merge Maps
def mergeMaps[A, B](map1: Map[A, Set[B]], map2: Map[A, Set[B]]): Map[A, Set[B]] = {
(map1.toSeq ++ map2.toSeq).groupBy(_._1).mapValues(_.map(_._2).toSet).mapValues(_.flatten)
}
@nelanka
nelanka / Default (Windows).sublime-keymap
Created October 16, 2014 14:03
Sublime Text 3 - User Key Bindings (IntelliJ IDEA Style) - Windows
[
{ "keys": ["ctrl+y"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
{ "keys": ["ctrl+d"], "command": "duplicate_line" }
]
@nelanka
nelanka / Enumerations.scala
Last active March 17, 2016 22:20
Scala Enumerations
object ActionType extends Enumeration {
type ActionType = Value
val GET = Value("Get")
val SET = Value("Set")
implicit def stringToActionType(action: String): ActionType = action match {
case "Get" => GET
case "Set" => SET
}
}
@nelanka
nelanka / Default (OS X).sublime-keymap
Last active November 15, 2019 03:10
Sublime Text 3 - User Key Bindings (IntelliJ IDEA Style) - OS X
[
{ "keys": ["super+y"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
// { "keys": ["super+d"], "command": "duplicate_line" }, -- Default is super+shift+D
{ "keys": ["super+`"], "command": "toggle_side_bar" },
{ "keys": ["super+shift+up"], "command": "swap_line_up" },
{ "keys": ["super+shift+down"], "command": "swap_line_down" },
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },
{ "keys": ["alt+m"], "command": "markdown_preview", "args": {"target": "browser", "parser":"markdown"} }
]
@nelanka
nelanka / grep.sh
Created October 24, 2014 13:38
Grep-Fu!
grep -o '.\{0,20\}test_pattern.\{0,20\}' –
portion on left is how many characters before match and portion on right is how many characters after match
using this to pull out unique RICS from a json string where they are suffixed by the text (RIC)
grep -o '.\{0,7\}(RIC).\{0,0\}' junitResult.xml | uniq | sort | cut -d " " -f 1
@nelanka
nelanka / vimrc
Last active March 7, 2016 21:17
vimrc
" Use bash shell to run scripts (fish isn't POSIX compliant)
set shell=bash
" Vundle Config [Package Manager for Vim] - https://github.com/VundleVim/Vundle.vim
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
@nelanka
nelanka / .gitignore
Created November 25, 2014 03:46
Git Ignore File
*.class
*.log
# mine
.idea
build
target
logs
.gradle
data