Skip to content

Instantly share code, notes, and snippets.

View crudh's full-sized avatar

Christian Rudh crudh

View GitHub Profile

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@crudh
crudh / restart_audio.sh
Created December 11, 2016 18:59 — forked from viktorklang/restart_audio.sh
Emergency audio reset on OS X / macOS when faced with loss of audio
#Use at your own risk. No warranties expressed or implied. YMMV. Drive responsibly. Eat healthy.
#for ZSH, I typically put these in my .zshrc
function restart_audio() {
command sudo killall coreaudiod &&
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist &&
sudo launchctl load /System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist &&
echo 'Audio daemon restarted'
}
@crudh
crudh / .bash_profile
Created December 14, 2015 20:59
Terminal configuration
PS1='\[\e[0;33m\]\h:\W \u\$\[\e[m\] '
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
export LC_MESSAGES="en_US.UTF-8"
alias mv='mv -i'
alias rm='rm -i'
alias cp='cp -i'
alias ls='ls -GF'

Keybase proof

I hereby claim:

  • I am crudh on github.
  • I am crudh (https://keybase.io/crudh) on keybase.
  • I have a public key whose fingerprint is 0D56 584D FE63 CAC7 FDCC 054F 2E1B 5E5D 4404 227C

To claim this, I am signing this object:

@crudh
crudh / PayloadEventDispatcher.java
Created August 31, 2014 18:34
Simple not optimized Apache Wicket IEventDispatcher implementation
public class MyPayloadEventDispatcher implements IEventDispatcher {
@Override
public void dispatchEvent(Object sink, IEvent event, Component component) {
// Check that the payload isn't null and that the sink, the receiver, has the annotation
if (event.getPayload() != null && sink.getClass().isAnnotationPresent(EventPayloadReceiver.class)) {
EventPayloadReceiver eventReceiver = sink.getClass().getAnnotation(EventPayloadReceiver.class);
// Check that the annotation is configured with the current event
if (Arrays.asList(eventReceiver.value()).contains(event.getPayload().getClass())) {
@crudh
crudh / PlayRss.scala
Created August 31, 2014 16:34
Scala/Play RSS example
def rss = Action { implicit request =>
Ok(
<rss version="2.0">
<channel>
<title>News Application</title>
<link>{ routes.Application.index.absoluteURL(false) }</link>
<description>News Application</description>
{ NewsArticle.all.map { newsArticle =>
<item>
<title>{ newsArticle.title }</title>
@crudh
crudh / CoherenceInfo
Created August 31, 2014 16:18
Example code on how to get info about a Coherence cluster and caches
import java.util.Enumeration;
import java.util.List;
import com.tangosol.coherence.component.net.Member;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.CacheService;
import com.tangosol.net.Cluster;
import com.tangosol.net.NamedCache;
import com.tangosol.net.Service;
@crudh
crudh / find-windows-newlines.sh
Last active January 2, 2016 16:39
Find all files with Windows line endings.
grep -IUrl $'\r' .
@crudh
crudh / .gitconfig
Last active January 1, 2016 19:19
Great color config for git. Found it here: http://nathanhoad.net/how-to-colours-in-git. Added other settings.
[core]
pager = less -+S
[push]
default = current
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
@crudh
crudh / mongo-backup.sh
Created September 25, 2013 08:35
Exports MongoDB to BSON, creates an archive and mails it for backup purposes. Make sure that mailx is installed and in the path.
#!/bin/sh
# CONFIGURE THIS
outputBase=/Users/crudh/Code/shell-scripts/mongo-backup/test
resultPrefix=system-name
mailSubject="Backup - mongodb"
mailBody="Backup - mongodb"
mailRecipient=christian@primian.se
# DO NOT CHANGE BELOW HERE--------------------------