Skip to content

Instantly share code, notes, and snippets.

View anderssonfilip's full-sized avatar

Filip Andersson anderssonfilip

View GitHub Profile
@anderssonfilip
anderssonfilip / RandomGenerators.sc
Created November 9, 2013 16:30
Random Generators
trait Generator[+T] {
self =>
def generate: T
def map[S](f: T => S): Generator[S] = new Generator[S] {
def generate = f(self.generate)
}
def flatMap[S](f: T => Generator[S]): Generator[S] = new Generator[S] {
@anderssonfilip
anderssonfilip / LoadAsync
Created December 10, 2013 10:59
Example of using AsyncSeq{...} to asynchronously load similar data from tables
open Devart.Data
open Devart.Data.Oracle // http://www.devart.com/dotconnect/oracle/download.html
open FSharp.Control // https://github.com/tpetricek/FSharp.AsyncExtensions
open System
open System.Data
let sql = "SELECT * FROM {}"
let tables = [|"t1";"t2";"t3";"t4";"t5";"t6"|]
@anderssonfilip
anderssonfilip / Load
Last active December 30, 2015 21:39
Example of using seq{...} to load similar data from tables. To demonstrate difference between synchronous and asynchronous sequences
open Devart.Data
open Devart.Data.Oracle // http://www.devart.com/dotconnect/oracle/download.html
open FSharp.Control // https://github.com/tpetricek/FSharp.AsyncExtensions
open System
open System.Data
let sql = "SELECT * FROM {}"
let tables = [|"t1";"t2";"t3";"t4";"t5";"t6"|]
@anderssonfilip
anderssonfilip / gist:8955589
Last active February 15, 2022 07:05
Simple Python script to archive older files in a folder by tagging
import os
import glob
from datetime import date, timedelta
import re
from time import gmtime, strftime
folder = '<Insert folder name here>'
files = ['FileA.txt', 'FileB.txt']
archivePeriod = 5 # archive period in days
@anderssonfilip
anderssonfilip / gist:8955633
Last active August 29, 2015 13:56
Simple Python script to cap disk space of a folder
import os
cap = 1 # cap in Megabytes
from datetime import date, timedelta
from time import gmtime
cutoffDate = date.today()-timedelta(days=1) # does not delete files newer than this (exclusive of the date)
def GetFolderSize(start_path = '.'): #get disk space in Megabytes
return sum(os.path.getsize(f) for f in os.listdir('.') if os.path.isfile(f)) / (1024*1024)
class PairOfShoes(var leftSize: Int, var rightSize: Int) {
def mix(newLeftSize: Int, newRightSize: Int) =
{
leftSize = newLeftSize
rightSize = newRightSize
}
override def hashCode(): Int = leftSize + 31 * rightSize
def canEqual(that: Any): Boolean = that match {
@anderssonfilip
anderssonfilip / gist:9528419
Last active August 29, 2015 13:57
Spray Client example
// Akka Actor system
import akka.actor.ActorSystem
// HTTP related imports
import spray.http.{ HttpRequest, HttpResponse }
import spray.client.pipelining.{ Get, sendReceive }
// Futures related imports
import scala.concurrent.Future
import scala.util.{ Success, Failure }
@anderssonfilip
anderssonfilip / DirectEmbedding
Last active August 29, 2015 13:57
Slick direct Coffees
@table(name="COFFEES")
case class Coffee(
@column(name="NAME")
name : String,
@column(name="PRICE")
price : Double
)
@anderssonfilip
anderssonfilip / LiftedEmbedding
Last active August 29, 2015 13:57
Slick lifted Coffees
class Coffees(tag: Tag) extends Table[(String, Int, Double, Int, Int)]
(tag, "COFFEES") {
def name = column[String]("NAME", O.PrimaryKey)
def price = column[Double]("PRICE")
}
var ts: List[Long] = List.empty
def time[R](block: => R): R = {
val t0 = System.nanoTime()
val result = block
val t1 = System.nanoTime()
val t = t1 - t0
ts = ts ++ List(t)
result
}