Skip to content

Instantly share code, notes, and snippets.

@tyrcho
tyrcho / OpenWithSublimeText2.bat
Created May 11, 2016 14:17 — forked from mrchief/LICENSE.md
Add "Open with Sublime Text 2" to Windows Explorer Context Menu (including folders)
@echo off
SET st2Path=C:\Program Files\Sublime Text 2\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tyrcho
tyrcho / UniqueBy.scala
Created April 7, 2016 16:35
Filter an iterator by keeping only the lines which are unique by a transformation function
import scala.collection.AbstractIterator
import scala.collection.Iterator
object UniqueBy extends App {
val lines = io.Source.fromFile("""somefile""").getLines
uniqueBy(lines)(_.trim.headOption.getOrElse("")).foreach(println)
def uniqueBy[T, U](it: Iterator[T])(pred: T => U) = new AbstractIterator[T] {
@tyrcho
tyrcho / Basics.scala
Last active March 6, 2018 13:10
Scala CheatSheet
//Values and definitions
val x = 5 // constant, evaluated once
def y = 5 // definition (function), evaluated at each call
lazy val z = 5 // constant with lazy evaluation
var v = 5 // variable, only use when really needed
//Control constructs
if (true) 1 else 2 // conditional _expression_, of type Int
@tyrcho
tyrcho / config
Created March 9, 2016 09:23
ssh configuration to connect through a bastion (gateway)
Host *
ServerAliveInterval 60
StrictHostKeyChecking no
Host dockercobai
Hostname oscobai064s
ProxyCommand ssh -W %h:%p bastion
ForwardAgent yes
User www
IdentityFile "/c/Utilisateurs/a518291/.ssh/id_rsa_bastion"
class BowlingGame {
var moves = Vector.empty[Int]
def roll(i: Int) = {
moves = moves :+ i
}
def score: Int = score()
@tyrcho
tyrcho / recunzip.sh
Last active November 27, 2023 16:40
recursively unzip jar, war, ear files
#inspired by http://unix.stackexchange.com/questions/4367/extracting-nested-zip-files
while [ "`find . -type f -name '*.?ar' | wc -l`" -gt 0 ]; do 1 ↵
find . -type f -name "*.?ar" \
-exec mkdir -p '{}.dir' \; \
-exec echo "unzipping "{}" to "{}".dir" \; \
-exec unzip -o -d '{}.dir' -- '{}' \; \
-exec rm -- '{}' \;;
done
@tyrcho
tyrcho / App.java
Created January 18, 2016 13:08
Water Pouring : functional approach (scala, java 8)
package jm.desprez.bucketproblem;
import javaslang.Function1;
import javaslang.collection.LinkedHashSet;
import javaslang.collection.List;
import javaslang.collection.Set;
import javaslang.collection.Stream;
import javaslang.control.Option;
import lombok.AllArgsConstructor;
import lombok.Data;
@tyrcho
tyrcho / JsonDemo.scala
Created January 7, 2016 13:40
Parse and Serialize in JSON using rapture.io
import rapture.json._
import rapture.json.jsonBackends.jackson._
import rapture._
object JsonDemo extends App {
val p1 = Person("toto", List(Address("du chat", 3, "Lille")), None)
val p2 = Person("titi", List(Address("du chien", 2, "Lille")), Some("maid"))
val jsonStr = Json(List(p1, p2)).toString
println(jsonStr)
log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue<%an>%Creset' --abbrev-commit --date=relative --all
git log --pretty=format:"[%h] %an %ad %s" --numstat --date=short
git log --pretty=format:"[%h] %an %ad %s" --numstat --date=short --follow FILENAME
rem get all commits ids from auser, from all branches
git log --pretty=format:"%H" --author=auser --all
rem diff at character level instead of line