Skip to content

Instantly share code, notes, and snippets.

View lucianenache's full-sized avatar
💭
λ

Lucian Enache lucianenache

💭
λ
View GitHub Profile
@lucianenache
lucianenache / java-8-ami.md
Created January 27, 2016 09:00 — forked from rtfpessoa/java-8-ami.md
[Guide] Install Sun Java 8 on Amazon EC2 Ami

First verify the version of Java being used is not Sun Java 8 SDK

java -version

Get the Sun Java 8 SDK from Oracle

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" "http://download.oracle.com/otn-pub/java/jdk/8u11-b12/jdk-8u11-linux-x64.rpm"

Install Sun Java 8

sudo rpm -i jdk-8u11-linux-x64.rpm

Check if the default java version is set to Sun Java 8 SDK

Get Git log in JSON format

git log --pretty=format:'{%n  "commit": "%H",%n  "abbreviated_commit": "%h",%n  "tree": "%T",%n  "abbreviated_tree": "%t",%n  "parent": "%P",%n  "abbreviated_parent": "%p",%n  "refs": "%D",%n  "encoding": "%e",%n  "subject": "%s",%n  "sanitized_subject_line": "%f",%n  "body": "%b",%n  "commit_notes": "%N",%n  "verification_flag": "%G?",%n  "signer": "%GS",%n  "signer_key": "%GK",%n  "author": {%n    "name": "%aN",%n    "email": "%aE",%n    "date": "%aD"%n  },%n  "commiter": {%n    "name": "%cN",%n    "email": "%cE",%n    "date": "%cD"%n  }%n},'

The only information that aren't fetched are:

  • %B: raw body (unwrapped subject and body)
  • %GG: raw verification message from GPG for a signed commit
@lucianenache
lucianenache / Scala_constructs.scala
Last active February 9, 2016 20:46
Scala constructs document for resolving futures, options, and other monadic types
//////////////////////////////////////////// Option ////////////////////////////////////////////////////////////////////////
obj.fold(defaultVal)(func)
obj.map(func).getOrElse(defaultVal)
obj match {
case Some(x) => func(x);
case None => defaultVal
}
// composed Option[A]
val oa: Option[String] = Some("a")

Keybase proof

I hereby claim:

  • I am lucianenache on github.
  • I am lucian_enache (https://keybase.io/lucian_enache) on keybase.
  • I have a public key whose fingerprint is E349 CC65 D191 930C D888 F808 CCAD 6783 8C82 C1EB

To claim this, I am signing this object:

/* proof of concept for non atomic method */
/* to fix this the call should be wrapped */
/* inside a synchronized block */
private var uidCount = 0L
def getUniqueId(): Long = {
uidCount = uidCount + 1
uidCount
}
@lucianenache
lucianenache / TestMultipartFileUpload.scala
Created June 1, 2016 10:43 — forked from jrudolph/TestMultipartFileUpload.scala
akka-http Multipart file-upload client + server example
package akka.http.scaladsl
import java.io.File
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.util.ByteString
import scala.concurrent.duration._
import akka.actor.ActorSystem
@lucianenache
lucianenache / gist:60a0b82f02facebfecf76fe5bb52314a
Created October 12, 2016 14:22 — forked from manjuraj/gist:8c767ac4d6814be2813e
collect vs map, filter vs flatMap
// The collect method takes a PartialFunction as argument and maps the
// values defined for this partial function over it, skipping those
// outside the definition domain.
// Given a partial function pf, the following code:
//
// val pf: PartialFunction[A, B] =
// coll.collect(pf)
//
// is roughly equivalent to
@lucianenache
lucianenache / latency.txt
Created January 31, 2017 19:44 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@lucianenache
lucianenache / esp32_temp.c.ino
Last active March 20, 2019 21:34
temperature reader from lm35 (look into dht11/12)
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
int analogPin = A0;
const char* ssid = "SOME_SSID";
const char* passwd = "SOME_PASSWD";
AsyncWebServer server(80);
float readTemp() {
@lucianenache
lucianenache / SpringBootDemo.java
Created March 27, 2019 15:04
Spring Boot procedural, lambda and reactive
/* Procedural endpoint */
@GetMapping("/users/{id}")
ResponseEntity<User> get(@PathVariable long id) {
User user = repository.findById(id);
if(user != null) {
return ok(user);
} else {
return notFound();
}
}