Skip to content

Instantly share code, notes, and snippets.

View GMadorell's full-sized avatar
🏗️
Building stuff

Gerard Madorell GMadorell

🏗️
Building stuff
View GitHub Profile
@GMadorell
GMadorell / accumulate.scala
Created September 30, 2018 18:52
Software Crafters Barcelona 2018 - Open Space Monadic Refactor Workshop
import cats.{Id, Monad}
import cats.implicits._
object AccumulateConventional extends App {
trait Console {
def write(text: String): Unit
def read(): String
}
@GMadorell
GMadorell / genesis_public_key
Created February 21, 2018 15:28
genesis_public_key
04ec44b00cfb41006348b0e9eb8dc855133acada345f3a1f5bc1700b5582be3e10b0d3870dc7fc47c2e7913a2f138d37e47fb730e19f1aea20dde2134bfa5d85c5
@GMadorell
GMadorell / scala-bootstrap
Created September 21, 2016 09:54
Bootstrap a scala application structure
#!/bin/bash
set -e
PROJECT_NAME="$1"
SCALA_VERSION="2.11.8"
SCALATEST_VERSION="3.0.0"
echo " . Creating project folder with name: $PROJECT_NAME..."
mkdir $PROJECT_NAME
@GMadorell
GMadorell / mongo_test.java
Last active August 29, 2015 14:21
mongo_test
import com.mongodb.*;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main {
static final String DELIMITER = "---------------\n";
@GMadorell
GMadorell / fizzbuzzscala
Created April 22, 2015 17:04
fizzbuzz scala
package fizzbuzz
object Fizzbuzz {
def fizzbuzz(n: Int): String = n match {
case _ if (n % 3) == 0 && (n % 5) == 0 => "fizzbuzz"
case _ if (n % 3) == 0 => "fizz"
case _ if (n % 5) == 0 => "buzz"
case _ => ""
}
@GMadorell
GMadorell / cache_in_file.py
Created December 4, 2014 16:29
Cache the result of a function as a pickle dump so we don't have to load it again the next time we want to use it.
def cache_in_file(filepath, object_creation_function):
if os.path.exists(filepath):
with open(filepath, "r") as dump_file:
obj = pickle.load(dump_file)
else:
obj = object_creation_function()
with open(filepath, "w") as dump_file:
pickle.dump(obj, dump_file)
return obj
@GMadorell
GMadorell / backup.py
Last active August 29, 2015 14:08
backup a file in python
def backup_file(file_path, backup_path=None, verbose=True):
"""
If the given 'file_path' exists, this function creates a copy of it.
Backup is done at 'backup_path'.backup# (backup_path defaults to
'file_path'.
If 'verbose' is set (defaults to True), prints output when backing up.
"""
if not os.path.isfile(file_path):
return
if not backup_path:
@GMadorell
GMadorell / pathing.py
Created October 7, 2014 22:23
Pathing. Easy way to evade the pathing problems when running an script in python.
import os
TOP_LEVEL_NAME = "lorayne_numbers"
def __get_current_path():
return os.path.dirname(os.path.abspath(__file__))
def get_top_level_path():

Keybase proof

I hereby claim:

  • I am skabed on github.
  • I am gmadorell (https://keybase.io/gmadorell) on keybase.
  • I have a public key whose fingerprint is 897E 80B3 E945 C2C4 6BAE 0E79 BEC3 5ED9 C941 7C2F

To claim this, I am signing this object:

@GMadorell
GMadorell / find_unique_rows.py
Created May 17, 2014 19:25
Find unique rows (submatrices) in a given matrix.
import numpy as np
# http://stackoverflow.com/questions/16970982/find-unique-rows-in-numpy-array
def find_unique_rows(array):
b = array[np.lexsort(array.reshape((array.shape[0],-1)).T)];
return b[np.concatenate(([True], np.any(b[1:]!=b[:-1], axis=tuple(range(1,array.ndim)))))]
if __name__ == "__main__":