Skip to content

Instantly share code, notes, and snippets.

View Tolsi's full-sized avatar
⌨️
I am jumping on the keyboard

Sergey Tolmachev Tolsi

⌨️
I am jumping on the keyboard
View GitHub Profile
@ArtemGr
ArtemGr / alternative, using regex
Created May 21, 2009 16:29
CSV parser in Scala
val pattern = java.util.regex.Pattern.compile ("""(?xs) ("(.*?)"|) ; ("(.*?)"|) (?: \r?\n | \z ) """)
val matcher = pattern.matcher (input)
while (matcher.find) {
val col1 = matcher.group (2)
val col2 = matcher.group (4)
// ...
}
@wickman
wickman / case_class.py
Created March 7, 2011 01:02
case-class like thing in python
# E.g. TaskClass = CaseClass('name', 'owner', 'pid')
# task1 = TaskClass(name = "hello", owner = "brian", pid = 15)
# task2 = TaskClass(name = "world", owner = "brian", pid = 13)
# tasks = [task1, task2]
#
# filter(lambda task: task.where(owner = "brian"), tasks) => [task1, task2]
# filter(lambda task: task.where(owner = "brian", pid = 13), tasks) => [task2]
#
# matcher = TaskClass(pid = 13)
# filter(lambda task: task.match(matcher), tasks) => [task2]
@remeniuk
remeniuk / GameSpec.scala
Created April 10, 2011 10:58
Type-safe Tic-Tac-Toe
package com.vasilrem.ttt
import org.specs._
class GameSpecs extends Specification{
implicit def toOption[A, B](either: Either[A, B]): Option[B] =
either.right.toOption
"Play a winning game" in {
@esperlu
esperlu / mysql2sqlite.sh
Created April 27, 2011 05:46
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@gclaramunt
gclaramunt / Circularbuffer.scala
Created November 23, 2011 17:33
circular buffer
package my.collections
class CirculrBufferIterator[T](buffer:Array[T], start:Int) extends Iterator[T]{
var idx=0
override def hasNext = idx<buffer.size
override def next()={
val i=idx
idx=idx+1
buffer(i)
}
@jcaraballo
jcaraballo / git-branch-between-different-repositories.md
Created March 6, 2012 01:05
How to fork a github repository in bitbucket

#Create bitbucket branch

##Create local branch

$ git checkout -b sync
Switched to a new branch 'sync'
$ git branch
  master
* sync
@guillaumebort
guillaumebort / Secured.scala
Created April 7, 2012 12:05
HTTP Basic Authorization for Play 2.0
def Secured[A](username: String, password: String)(action: Action[A]) = Action(action.parser) { request =>
request.headers.get("Authorization").flatMap { authorization =>
authorization.split(" ").drop(1).headOption.filter { encoded =>
new String(org.apache.commons.codec.binary.Base64.decodeBase64(encoded.getBytes)).split(":").toList match {
case u :: p :: Nil if u == username && password == p => true
case _ => false
}
}.map(_ => action(request))
}.getOrElse {
Unauthorized.withHeaders("WWW-Authenticate" -> """Basic realm="Secured"""")
@viktorklang
viktorklang / minscalaactors.scala
Last active March 25, 2024 19:01
Minimalist Scala Actors
/*
Copyright 2012-2021 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@laszlomiklosik
laszlomiklosik / Install flash player debug version on Ubuntu 64 bit
Created June 2, 2012 08:20
Install Flash Player debug version in Ubuntu 12.04 64 bit
# no 64 bit version of the flash debug player is available, thus we will use the 32 bit version and use nspluginwrapper to make it work
sudo killall -9 firefox
sudo apt-get remove -y --purge flashplugin-nonfree gnash gnash-common mozilla-plugin-gnash swfdec-mozilla libflashsupport nspluginwrapper
sudo rm -f /usr/lib/mozilla/plugins/*flash*
sudo rm -f ~/.mozilla/plugins/*flash*
sudo rm -f /usr/lib/firefox/plugins/*flash*
sudo rm -f /usr/lib/firefox-addons/plugins/*flash*
sudo apt-get install ia32-libs nspluginwrapper libcurl3 libnss3-1d libnspr4-0d
cd ~
@patriknw
patriknw / ClusterDemoSpec.scala
Created July 6, 2012 09:59
Sample of akka cluster test
package akka.cluster
import com.typesafe.config.ConfigFactory
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.testkit._
import akka.util.duration._
import akka.cluster.MemberStatus._
object ClusterDemoMultiJvmSpec extends MultiNodeConfig {