Skip to content

Instantly share code, notes, and snippets.

View gabriel-bezerra's full-sized avatar

Gabriel Assis Bezerra gabriel-bezerra

View GitHub Profile
@dragisak
dragisak / DateTimeMapper.scala
Created February 11, 2013 18:17
Joda DateTime mapper in Slick
import slick.lifted.MappedTypeMapper
import java.sql.Date
import org.joda.time.DateTime
import slick.lifted.TypeMapper.DateTypeMapper
object DateTimeMapper {
implicit def date2dateTime = MappedTypeMapper.base[DateTime, Date] (
dateTime => new Date(dateTime.getMillis),
date => new DateTime(date)
@willurd
willurd / web-servers.md
Last active July 23, 2024 17:12
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@kachayev
kachayev / skew.hs
Last active July 10, 2018 16:52
Skew Heap implementation in Haskell
data Skew a = Empty | Node a (Skew a) (Skew a)
singleton :: Ord a => a -> Skew a
singleton x = Node x Empty Empty
union :: Ord a => Skew a -> Skew a -> Skew a
union t1 Empty = t1
union Emtpy t2 = t2
union t1@(Node x1 l1 r1) t2@(Node x2 l2 r2)
| x1 <= x2 = Node x1 (union t2 r1) l1
@propensive
propensive / heteroargs.scala
Created January 31, 2015 20:03
Easy Heterogeneous Varargs in Scala
// Define the general Arg type and companion object:
import language.higherKinds, language.implicitConversions, language.existentials
object Arg { implicit def toArg[Tc[_], T: Tc](t: T): Arg[T, Tc] = Arg(t, implicitly[Tc[T]]) }
case class Arg[T, Tc[_]](value: T, typeclass: Tc[T])
// Say, for example we have a typeclass for getting the length of something, with a few instances
trait Lengthable[T] { def length(t: T): Int }
implicit val intLength = new Lengthable[Int] { def length(i: Int) = 1 }
implicit val stringLength = new Lengthable[String] { def length(s: String) = s.length }
@spaced
spaced / GoogleAnalytics.scala
Last active May 25, 2016 04:48
Small Scalajs facade for google analytics events
object EventTracker {
def isScriptLoaded=js.Dynamic.global.ga.isInstanceOf[js.Function]
def sendEvent(category:String,action:String,label:String):Unit={
if (isScriptLoaded) GoogleAnalytics.ga("send","event",category,action,label)
}
def sendEvent(category:String,action:String,label:String,value:String):Unit={
if (isScriptLoaded) GoogleAnalytics.ga("send","event",category,action,label,value)
}
}
@cscalfani
cscalfani / CompositionWithMultipleParameters.md
Created December 5, 2017 22:29
Functional Composition with Multiple Parameters in Haskell

Functional Composition with Multiple Parameters in Haskell

In the past, I've written composition functions in both Elm and Haskell that take multiple parameters for the leftmost function, i.e. the function that gets applied first.

(All examples here are in Haskell)

Here was my Haskell implemenation (stolen from the web):

compose2 :: (c -&gt; d) -&gt; (a -&gt; b -&gt; c) -&gt; a -&gt; b -&gt; d
@non
non / Diagonal.scala
Last active February 13, 2018 19:29
Initial thoughts on creating efficient ways to index into arbitrary enumerations of all values of a type.
package kronecker
import spire.implicits._
/**
* Utilities for doing diagonalization in N dimensions.
*
* The goal here is to be able to support diagonalizations for
* arbitrary tuples, e.g. Tuple2, Tuple3, Tuple9, etc. The "dimension"
* (or "dim") represents the arity of the tuple: dim=2 would

Provisional benchmarks of AST-free serialization puts my WIP branch of uPickle about ~40% faster than circe on my current set of ad-hoc benchmarks, if the encoders/decoders are cached (bigger numbers is better)

playJson Read 2761067
playJson Write 3412630
circe Read 6005895
circe Write 5205007
upickleDefault Read 4543628
upickleDefault Write 3814459
upickleLegacy Read 8393416
@milessabin
milessabin / typelevelcps.scala
Created May 29, 2018 10:13
Using type level continuation passing style to rewrite a whitebox macro (which relies on fundep materialization) as a blackbox macro
import scala.language.higherKinds
// Whitebox ...
trait Schema[T, R] {
def conv(t: T): R
}
object Schema {
// Whitebox macro: R is computed from T
implicit def mkSchema[T, R]: Schema[T, R] = ??? // macro ...
@geek-at
geek-at / smartmeter.ino
Created October 19, 2018 08:34
Example script to log flashing light to influxdb via UDP. See https://blog.haschek.at/smartmeter for more info
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
WiFiUDP Udp;
const char* ssid = "yourwifiSSID";
const char* password = "yourwifipassword";
const int threshold = 400; //this is the threshold how high the value has to be to be registered as a flash.
//400 works great for me since flashes are usually ~600
IPAddress remoteIP(192,168,1,117); // the IP address of your Influxdb server