Skip to content

Instantly share code, notes, and snippets.

View onegrx's full-sized avatar

Bartłomiej Szałach onegrx

  • Kraków, Poland
View GitHub Profile
@onegrx
onegrx / Config.ex
Last active April 24, 2017 23:57
Fetch config from keyword list
defmodule Config do
def get(key, default) do
# Sample config
vars = [key1: :val1,
key2: [nested_key1: :nested_val1,
nested_key2: :nested_val2]]
get(key, vars, default)
end
@onegrx
onegrx / dht11.cpp
Created April 16, 2017 23:25
DHT11 library in C++ for Arduino
#include "dht11.h"
// There is a timeout if voltage on pin does not change in 10k loop passes time
bool acknowledge(int pin, int mode) {
for(unsigned int loopCnt = 10000; digitalRead(pin) == mode; loopCnt--) {
if (loopCnt <= 0) return false;
}
return true;
}
import java.text.SimpleDateFormat
import java.util.{Calendar, Date}
object Sessions extends App {
def survey(logs: List[String]): Boolean = {
val formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
val dates: List[Date] = logs.map(formatter.parse).sortBy(_.getTime)
object Primes extends App {
def process(A: List[Int], B: List[Int]) = {
def isPrime(n: Int): Boolean = {
if (n == 2) true
else if (n < 2 || n % 2 == 0) false
else Stream.from(3, 2).takeWhile(i => i * i <= n).forall(n % _ != 0)
}
#*****************************************************************
# Neo4j configuration
#
# For more details and a complete list of settings, please see
# https://neo4j.com/docs/operations-manual/current/reference/#configuration-settings
#*****************************************************************
# The name of the database to mount
dbms.active_database=default.graphdb
@onegrx
onegrx / neo4j.txt
Last active January 11, 2017 12:49
Neo4j examples
MATCH (movie:Movie)
WHERE movie.year = 2016
RETURN movie.title AS title
ORDER BY title ASC LIMIT 25
MATCH (m:Movie {title: "Star Wars"})<-[:DIRECTED]-(p:Person {})
RETURN p.name, m.title
MATCH (a:Person {name: "Emma Watson II"})-[:ACTED_IN]-(m)<-[:ACTED_IN]-(coActors)
RETURN coActors.name
/usr/lib/jvm/java-8-oracle/bin/java -Didea.launcher.port=7534 -Didea.launcher.bin.path=/home/onegrx/apps/idea-IU-162.2228.15/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre
body {
background-color: #333333;
text-align: center;
color: #33b5d3;
font-size: 22px;
font-family: 'Gloria Hallelujah', cursive;
}
p {
display: inline;
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
import scala.collection.JavaConversions._
import java.net.{ URL, MalformedURLException }
import scala.util.control.Exception._
sealed case class Link(title: String, href: String)
@onegrx
onegrx / 0.md
Created May 16, 2016 01:43 — forked from max-mapper/0.md
JS hoisting by example

JavaScript function hoisting by example

Below are many examples of function hoisting behavior in JavaScript. Ones marked as works successfuly print 'hi!' without errors.

To play around with these examples (recommended) clone them with git and execute them with e.g. node a.js

Notes on hoisting

(I may be using incorrect terms below, please forgive me)