Skip to content

Instantly share code, notes, and snippets.

Avatar

Hannes Tydén hannestyden

  • Berlin, Germany
View GitHub Profile
View Beither.scala
abstract class Beither[+A, +B] {
// From German "beide" and English "either" => "beither".
// Preferably pronounced as German "Beißer".
def left = Beither.LeftProjection(this)
def right = Beither.RightProjection(this)
def both = Beither.BothProjection(this)
}
@hannestyden
hannestyden / open-mysql-docker-service-in-sequel-pro.sh
Last active May 26, 2018 — forked from helderco/db-open
Script to open a mysql database in Sequel Pro from a service in docker-compose.
View open-mysql-docker-service-in-sequel-pro.sh
#!/bin/bash
# Original: https://gist.github.com/helderco/e9d8d072a362ad818f6a
set -e
show_help() {
cat << EOF
Usage: ${0##*/} [-s SERV] [-u USER] [-p PASS] [-P PORT] [-H HOST] [DATABASE]
${0##*/} -h
@hannestyden
hannestyden / Gemfile
Last active Apr 8, 2018 — forked from jaredculp/das_download.rb
Destroy All Software downloader
View Gemfile
source 'https://rubygems.org' do
gem 'mechanize'
end
View x2j.zsh
# Convert XML to JSON
#
# Usage:
# x2j source_path [xsltjson parameters](https://github.com/bramstein/xsltjson#parameters)
#
# Reads from standard in if `source_path` set to `-`.
x2j() {
local base
base=src/github.com/bramstein/xsltjson
View lprompt.zsh
lprompt() {
r=$?
[ $r -eq 0 ] && echo "?" || echo "!"
}
@hannestyden
hannestyden / animal.rb
Last active Apr 8, 2018
Inheritence, mix-ins, composotion
View animal.rb
# Composition
class Eat
def do_it
puts 'Nom, nom ...'
end
end
class Say
def do_it
View whatIsMyName.scala
scala> def whatIsMyName[A,B](map: Map[A, Seq[B]]): List[(A, B)] =
| map.map { case (k, v) => v.map(k -> _) }.flatten.toList
whatIsMyName: [A, B](map: Map[A,Seq[B]])List[(A, B)]
scala> whatIsMyName(Map('a -> Seq(1,2), 'b -> Seq(3,4)))
res0: List[(Symbol, Int)] = List(('a,1), ('a,2), ('b,3), ('b,4))
View git-lye.sh
# git lye
# An attempt to make rebasing easy, by draining unnessarcy commit noise.
# No warranty, use at own risk.
# Author Hannes Tydén <hannes@tyden.name>
# Contributor Tobias Schmidt <ts@soundcloud.com>
# TODO
# - Don't sign off all commits are by current user.
View hash.rb
class Hash
alias_method :[], :fetch # !> method redefined; discarding old []
end
h = {a: 1}
h[:a] # => 1
h[:b] rescue $! # => #<KeyError: key not found: :b>
h[:b, 2] # => 2
View rescue_in_block.rb
class E < StandardError; end
def m(raise_exception)
y do
r(raise_exception)
:nothing_raised
end
rescue E
:rescued
end
You can’t perform that action at this time.