Skip to content

Instantly share code, notes, and snippets.

View lucaong's full-sized avatar

Luca Ongaro lucaong

View GitHub Profile
@lucaong
lucaong / minisearch-combiners.js
Created August 11, 2021 10:06
Sketch of combiners for MiniSearch results of different searches
/**
* Usage:
*
* import { and, or } from 'minisearch-combiner'
*
* and(resultsA, resultsB)
*
* or(resultsA, resultsB)
*
* and(or(resultsA, resultsB), resultsC)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Ore Trascorse</title>
<style id="jsbin-css">
* {
box-sizing: border-box;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Ore Trascorse</title>
<style id="jsbin-css">
body {
font-family: Helvetica, Arial, sans-serif;
font-size: 16px;
@lucaong
lucaong / bug.js
Created July 21, 2018 20:50
Safari bug
// Safari bug
// ==========
//
// Two strings, that share a prefix after a regexp normalization,
// are used as keys in an object. Then, they are traversed character
// by character and recomposed into another string by concatenation,
// and each is put in an array. When they are used to index the object,
// the second one is not found among the keys: the reason is that it
// contains a null byte (copy/paste it into a file and inspect the binary
// representation, e.g. with `xxd`, to see that).
@lucaong
lucaong / README.md
Last active February 13, 2018 13:44
Multiple SSIDs with NervesNetwork

Configuring multiple WiFi SSID on Nerves

This gist quickly demonstrates my setup to allow multiple WiFi SSID/PSK to be configured at the same time on Nerves. It relies on NervesNetwork, which is a dependency. Currently, this is bound to the "wlan0" interface, but it can be made more generic with little effort.

How it works

In the nerves_network configuration, I omit setting "wlan0" (I want to take care of it myself).

@lucaong
lucaong / keybase.md
Created February 13, 2017 14:55
keybase.md

Keybase proof

I hereby claim:

  • I am lucaong on github.
  • I am lucaongaro (https://keybase.io/lucaongaro) on keybase.
  • I have a public key whose fingerprint is EFBB F8B2 E4B5 049F FF03 0B70 4F68 D2C9 63E1 2946

To claim this, I am signing this object:

@lucaong
lucaong / atom.cr
Created February 8, 2016 22:56
Proof of concept of Clojure-like atom in Crystal
class Atom(T)
@state : T
@channel : Channel::Buffered({(T -> T), Channel::Buffered(T | ValidationError)})
@validator : T -> Bool
def initialize(@state : T, @validator = ->(i : T){ true } : T -> Bool)
@channel = Channel({(T -> T), Channel::Buffered(T | ValidationError)}).new(1)
spawn do
loop do
block, c = @channel.receive
@lucaong
lucaong / foo.rb
Last active August 17, 2017 06:18
Tail Call Optimization in Ruby
require './tail_call_optimization'
class Foo
extend ::TailCallOptimization
tailrec def fact(n, k = 1)
raise ArgumentError, 'n should be >= 1' if n < 1
return k if n == 1
fact(n - 1, n * k)
end
@lucaong
lucaong / benchmark.rb
Created April 1, 2015 12:05
Benchmark optimization on Rack::Builder
require 'rack'
require 'benchmark'
class OptimizedRackBuilder < Rack::Builder
def call(env)
@to_app ||= to_app
@to_app.call(env)
end
end
@lucaong
lucaong / lru_cache.js
Created September 29, 2014 23:59
JavaScript LRU cache implementation
var LRUCache = (function() {
function LRUCache(options) {
this._options = options || {}
this._map = {}
this._queue = {}
this._capacity = this._options.capacity || 10
this._size = 0
}
var _detachFromQueue = function(node, queue) {