Skip to content

Instantly share code, notes, and snippets.

View viktorklang's full-sized avatar

Viktor Klang (√) viktorklang

View GitHub Profile
@viktorklang
viktorklang / ToggleDock.applescript
Created May 27, 2014 11:24
AppleScript to toggle the use of Dock.app
(*
MIT License
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*)
on run {input, parameters}
set inactivePath to "/System/Library/CoreServices/Dock.app.bak"
set activePath to "/System/Library/CoreServices/Dock.app"
if application "Dock" is running then
@viktorklang
viktorklang / git-catchup.zsh
Created October 23, 2014 22:01
Git Catchup
#!/bin/zsh
#########################################################################################################################
# MIT License
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package gistard.test
object Verify extends App {
println("OK")
}
abstract class some[X](val value : X) { type T = X }
abstract class someFactory[S <: some[_]](val P : (S#T) => boolean)
{
def apply(t : S#T) : Option[S] = if(P(t)) Some(fetch(t)) else None
def unapply(s : S) : Option[S#T] = if(s == null) None else Some(s.value)
def fetch(t : S#T) = mk(t)
//isValid = predicate/constraint
abstract class Type[T](val isValid : (T) => boolean)
{
//X is the reference type
final protected[Type] case class X[T] (val value : T) {
override def toString = Type.this.getClass.getSimpleName + "(" + value + ")"
}
//Type is the alias for X[T] that we expose to the outside world
type Type = X[T]
object Test {
trait Mapping {
def get[T](clazz : Class[T]) : T
}
trait Injector {
protected val mapping : Mapping
def inject[T](implicit manifest : scala.reflect.Manifest[T]) = mapping.get(manifest.erasure.asInstanceOf[Class[T]])
}
//Usage:
//override def pomPostProcess(node: Node): Node = mcPom(moduleConfigurations)(super.pomPostProcess(node))
trait McPom { self: DefaultProject =>
import scala.xml._
def mcPom(mcs: Set[ModuleConfiguration])(node: Node): Node = {
//make sure we have a trailing slash so we deduplicate URLs properly
def cleanUrl(url: String) = url match {
case null => ""
@viktorklang
viktorklang / UnnestedReceives.scala
Created January 26, 2011 17:16
Unnesting a Scala Actors nested receive example
/**
* I had a question directed at me, on how to encode the following scenario in Akka Actors,
* as for Scala Actors one would simply nest the receives.
*
* Recuirements are as follows:
* The first thing the actor needs to do, is to subscribe to a channel of events,
* Then it must replay (process) all "old" events
* Then it has to wait for a GoAhead signal to begin processing the new events
* It mustn't "miss" events that happen between catching up with the old events and getting the GoAhead signal
*/
@viktorklang
viktorklang / MiniSTM.scala
Created February 9, 2011 18:06
Optimistic concurrency using AtomicReference
class MiniSTM[T <: AnyRef](initialValue: T) {
private val value = new AtomicReference[T](initialValue)
def apply(fun: T => T) {
@tailrec def update(expect: T): Unit =
if ( !value.compareAndSet(expect, fun(expect)) ) update(value.get)
update(value.get)
}
@viktorklang
viktorklang / PostStart.scala
Created March 5, 2011 23:13
PostStart implementation for Akka
trait PostStart { actor: Actor =>
def postStart: Unit
override def preStart {
actor.become {
case "PostStart" => try { postStart } finally { actor.unbecome }
}
actor.self ! "PostStart"
}
}