Skip to content

Instantly share code, notes, and snippets.

@sgabber
sgabber / phoneKeyboardToString.java
Created February 25, 2021 13:50
Converts phone digits to string
import java.util.HashMap;
class Scratch {
public static void main(String[] args) {
String s = "444 2 6 444 66 33 888 444 8 2 22 555 33";
HashMap<String, String> numToLetters = new HashMap<>();
numToLetters.put("2", "abc");
numToLetters.put("3", "def");
From camelcase to db column name
find
/([a-z_]*)([A-Z])(.*?$)/
replace with
/\1_\l\2\3/
repeatedly
@sgabber
sgabber / stringPrefixPostfixOperators.scala
Created September 26, 2019 09:42
testing prefix and postfix operators or just messing with strings
println("messing with strings")
implicit class Screamer(s:String) {
def ! = s.toUpperCase
def !(o:String) = s.toUpperCase + o.toLowerCase
def unary_! = s.toLowerCase
}
println("ciao"!)
@sgabber
sgabber / RepeatTest.scala
Last active September 20, 2019 08:22
implementing the repeat until (like do while) only with basic scala constructs
object RepeatTest {
class RepeatHelper(cmd: => Unit) {
def until(cond: => Boolean): Unit = if (cond) repeat(cmd)
}
def repeat(cmd: => Unit): RepeatHelper = {
cmd
new RepeatHelper(cmd)
}