Skip to content

Instantly share code, notes, and snippets.

@vkobel
vkobel / pascalTriangle.scala
Last active December 15, 2015 12:48
Simple scala function to compute the pascal triangle
package week1
object pascalTriangle {
def pascal(c: Int, r: Int): Int = {
if (r == 0 && c == 0) 1
else if (c < 0 || c > r + 1) 0
else pascal(c - 1, r - 1) + pascal(c, r - 1)
} //> pascal: (c: Int, r: Int)Int
@vkobel
vkobel / parenthesesBalancing.scala
Created March 28, 2013 13:21
Simple parentheses balancing method using tailrec
package week1
import scala.annotation.tailrec
object parenthesesBalancing {
def balance(chars: List[Char]): Boolean = {
def analyse(c: Char) =
if (c == '(') 1
@vkobel
vkobel / import.py
Created April 19, 2013 11:41
Import file which do: - SSH Download of a .sql.gz.gpg file - Decrypting it using GPG - Decompress line by line using gzip - Create requests (separated by ";" and run it on mysql) It also has a retry and try_once function to handle errors and automatically re-run a determined amount of time if needed
import sys
from datetime import datetime
import paramiko
import gzip
import gnupg
import MySQLdb
# apt-get install:
# python-paramiko
# python-mysqldb
@vkobel
vkobel / akkaActors.scala
Created April 23, 2013 19:40
Example of how a simple system of actor and futures works in akka and scala
package akkaActors
import akka.actor.{ Actor, ActorSystem, Props, PoisonPill }
import akka.pattern.ask // enable the use of ? or ask that return a future from an actor
import akka.util.Timeout
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global // import global execution context (implicit way)
class HelloActor extends Actor {
@vkobel
vkobel / futures.scala
Created April 23, 2013 19:43
Simple use of akka futures (now part of scala library)
package akkaActors
import scala.concurrent.Await // enable awaiting a future
import scala.concurrent.duration._ // enable convert in to ms n.seconds
import scala.concurrent.Future // Future function
import scala.concurrent.ExecutionContext.Implicits.global // import global execution context (implicit way)
object futureTest extends App {
// Create and begin execution of the Future
@vkobel
vkobel / build.sbt
Created April 23, 2013 19:48
sbt build file for akka actors dependencies
name := "Akka actors"
version := "1.0"
scalaVersion := "2.10.1"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.1.2"
@vkobel
vkobel / example.fs
Created April 29, 2013 06:29
Example F# file from Microsoft
// This sample will guide you through elements of the F# language.
//
// *******************************************************************************************************
// To execute the code in F# Interactive, highlight a section of code and press Alt-Enter or right-click
// and select "Execute in Interactive". You can open the F# Interactive Window from the "View" menu.
// *******************************************************************************************************
//
// For more about F#, see:
// http://fsharp.net
//
@vkobel
vkobel / IRepository.cs
Last active December 7, 2023 14:16
Generic C# .NET Repository pattern (interface + implementation)
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Data.GenericRepo {
public interface IRepository<T> : IDisposable where T : class {
T[] GetAll();
IQueryable<T> Query(Expression<Func<T, bool>> predicate);
@vkobel
vkobel / GenericPropertyMethods.cs
Created May 13, 2013 12:33
Simple extension methods for objects, generic and list of objects to get and set properties (and related stuff).
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Vkobel.ExtensionMethods {
public static class GenericPropertyMethods {
public static PropertyInfo GetProperty(this object obj, string name) {
return obj.GetType().GetProperty(name);
}
@vkobel
vkobel / gitignore.sh
Created May 14, 2013 07:25
git commands to update a non-working .gitignore file on the repository.
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"