Skip to content

Instantly share code, notes, and snippets.

View aloiscochard's full-sized avatar
🪄

Aloïs Cochard aloiscochard

🪄
View GitHub Profile
@aloiscochard
aloiscochard / gist:8c45fbf8c967880b80b33c2b77d66e88
Last active October 17, 2023 07:25
PinePhone Pro Survival
# Install
- Mobian latest weekly
- https://images.mobian.org/pinephonepro/weekly/
- Disable software updates
- Set timezone
- sudo apt install openssh-server
- Enable flatpak: flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
- Install flatpauk apps: Cinny, Pomodoro, Chromatic
- Sync: Nextcloud
@aloiscochard
aloiscochard / rest-ws-client.scala
Created May 13, 2011 09:35
Scala REST WebService Client
// Sample usage of ...
// - Dispatch (http://dispatch.databinder.net)
// - SJSON (https://github.com/debasishg/sjson)
// ... to create a basic REST Web Service client for Twitter API
import dispatch._
import scala.reflect.BeanInfo
import sjson.json.Serializer.SJSON
// Model
@aloiscochard
aloiscochard / gist:10062325
Created April 7, 2014 21:34
Golden Rules

"A designer knows he has achieved perfection not when there is nothing left to add,but when there is nothing left to take away." - Antoine de Saint-Exupéry

"One person's syntax is another person's semantics." -- Joseph Goguen

"Ugly programs are like ugly suspension bridges: they're much more liable to collapse than pretty ones, because the way humans (especially engineer-humans) perceive beauty is intimately related to our ability to process and understand complexity. A language that makes it hard to write elegant code makes it hard to write good code." - Eric S. Raymond

"It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures." - Alan J. Perlis

"Simple things should be simple and complex things should be possible." - Alan Kay

@aloiscochard
aloiscochard / Stream.scala
Created November 2, 2011 16:06
Scala [In]finite Stream Constructor
import Stream._
/** A possibly finite stream that repeatedly applies a given function to a start value.
*
* @param start the start value of the stream
* @param f the function that's repeatedly applied
* @return the stream returning the possibly finite sequence of values `start, f(start), f(f(start)), ...`
*/
def iterate[A](f: A => A, a: A): Stream[A] = unfold((x: A) => Some((x, f(x))), a)
@aloiscochard
aloiscochard / JSONPrettyFormat.scala
Created October 11, 2011 18:35
Scala JSON Pretty Formatter
import scala.util.parsing.json._
val prettyFormatter: JSONFormat.ValueFormatter = {
def create(level: Int): JSONFormat.ValueFormatter = (x: Any) => {
x match {
case s: String => "\"" + JSONFormat.quoteString(s) + "\""
case jo: JSONObject =>
"{\n" +
"\t" * (level + 1) +
jo.obj.map({
@aloiscochard
aloiscochard / qsbt.sh
Last active March 5, 2018 21:34
QuickSBT - Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
#!/usr/bin/env bash
############
# QuickSBT #
############
# Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
# http://github.com/aloiscochard / https://gist.github.com/4698501
# Error format for SBT, and shortcut to open SBT quickfix file :
@aloiscochard
aloiscochard / Action.scala
Created December 1, 2013 10:39
Slick monadic Actions
package slick
/**
* This is some code extracted from TimeOut codebase, demonstrating:
* - Use of tag typed to avoid mixing session of different DB
* - The use of the Reader Monad to compose Actions together and defer the choice of async/sync computation
*
* I remove the part where we can say if our operation are read only or not (to use different connection), in order to
* make things easier.
**/
@aloiscochard
aloiscochard / fun-deps.scala
Last active September 11, 2016 16:39
Fun with fun-deps in scala.
/*
object Test0 {
import scalaz.meta.Foo._
val s: String = 1024.bar
val i: Int = "test".bar
println(s) // bar
println(i) // 42
}
*/
@aloiscochard
aloiscochard / 0-common.Module.scala
Last active September 11, 2016 16:02
Dependency Injection in Scala without Cake Pattern
package com.acme
import com.typesafe.config.Config
trait Module {
implicit def config: Config
}
@aloiscochard
aloiscochard / oplog.hs
Created January 18, 2015 11:35
Tailing MongoDB OpLog in Haskell
{-# LANGUAGE OverloadedStrings #-}
module Mongolito where
import Control.Exception
import Control.Monad.IO.Class (liftIO)
import Database.MongoDB
import System.Log.Logger
localDb :: Database
localDb = "local"