Skip to content

Instantly share code, notes, and snippets.

View lucianenache's full-sized avatar
💭
λ

Lucian Enache lucianenache

💭
λ
View GitHub Profile
Commands marked with * may be preceded by a number, N.
      Notes in parentheses indicate the behavior if N is given.
      A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K.

  h  H                 Display this help.
  q  :q  Q  :Q  ZZ     Exit.
 ---------------------------------------------------------------------------

                           MOVING
@lucianenache
lucianenache / enzyme_render_diffs.md
Created November 5, 2019 14:14 — forked from fokusferit/enzyme_render_diffs.md
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@lucianenache
lucianenache / Stack.scala
Created April 4, 2019 21:29
Scala stack example with mutable types
case class Node(data: Int, next: Option[Node]= None)
class Stack(var head: Node, var size: Int = 1) {
def push(i: Int): Unit = {
head = Node(i, Some(head))
size += 1
}
def pop(): Option[Int] = {
@lucianenache
lucianenache / FS2S3.scala
Last active December 23, 2019 19:00
Scala FS2 stream to AWS S3 example
// SBT
name := "delete"
scalaVersion := "2.12.7"
libraryDependencies ++= Vector(
"co.fs2" %% "fs2-core" % "1.0.0",
"com.amazonaws" % "aws-java-sdk-s3" % "1.11.442"
)
@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();
}
}
@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 / 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 / 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 / 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
/* 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
}