Skip to content

Instantly share code, notes, and snippets.

iex(foo@10.12.165.73)29> Node.list |> Enum.map(fn node -> Enum.map(1..100, fn _ -> {us, :pong} = :timer.tc(Node, :ping, [node])
...(foo@10.12.165.73)29> us/2 end)|> Enum.reduce(fn x, sum -> sum + x end) end) |> Enum.map(fn x -> x / 100 end)
[413.585, 436.995]
import chess
import chess.pgn
import chess.engine
from chess import BLACK, WHITE
engine = chess.engine.SimpleEngine.popen_uci("./stockfish_20090216_x64_avx2")
import bz2
path = "lichess_db_standard_rated_2017-04.pgn.bz2"
f = bz2.open(path, "rt", encoding="ascii")
@vhf
vhf / foo.ex
Created September 25, 2020 11:04
Number of weekdays between two dates (elixir)
defmodule Foo do
def bar(first_day, second_day) do
days_between = Date.diff(second_day, first_day) + 1
dow1 = Date.day_of_week(second_day)
dow2 = Date.day_of_week(second_day)
weekend_days =
Kernel.floor((days_between + dow2) / 7 * 2) +
if(dow1 == 7, do: 1, else: 0) - if(dow2 == 6, do: 1, else: 0)
@vhf
vhf / fix-svg.js
Last active March 31, 2018 14:24
rehype svg attributes fix
// complete list of camelCase attributes
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute
const camelAttributes = [
'allowReorder', 'attributeName', 'attributeType', 'autoReverse',
'baseFrequency', 'baseProfile', 'calcMode', 'clipPathUnits', 'contentScriptType',
'contentStyleType', 'diffuseConstant', 'edgeMode', 'externalResourcesRequired',
'filterRes', 'filterUnits', 'glyphRef', 'gradientTransform', 'gradientUnits',
'kernelMatrix', 'kernelUnitLength', 'keyPoints', 'keySplines', 'keyTimes', 'lengthAdjust',
'limitingConeAngle', 'markerHeight', 'markerUnits', 'markerWidth', 'maskContentUnits',
'maskUnits', 'numOctaves', 'pathLength', 'patternContentUnits', 'patternTransform',
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vhf
vhf / example.js
Created July 13, 2017 16:39 — forked from Mayeu/example.js
Remark fix new lines for GitLab
const fixNewLine = require('./index.js')
const remark = require('remark')
text = "lol\nlol\n```\nlol\nlol\n```\n> lol\n> lol"
processed = remark()
.use(fixNewLine)
.processSync(text)
console.log(processed)

![](data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M224%20387.814V512L32 320l192-192v126.912C447.375 260.152 437.794 103.016 380.93 0 521.287 151.707 491.48 394.785 224 387.814z'/%3E%3C/svg%3E)

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
(function() {
var preTags = document.getElementsByTagName('pre');
var preWithHeaderInfo = preTags[0];
var preWithContent = preTags[2];
var lines = preWithContent.textContent.split('\n');
// get data about the formatting (changes between different versions of chrome)
var rgx = /^(0{8}:\s+)([0-9a-f]{2}\s+)[0-9a-f]{2}/m;
var match = rgx.exec(lines[0]);
[
feed: [
publisher: "webmaster@example.com",
updated: "Tue, 10 Jun 2003 09:41:01 GMT",
published_parsed: "Tue, 10 Jun 2003 04:00:00",
subtitle: "Liftoff to Space Exploration.",
language: "en-us",
links: [
[
href: "http://liftoff.msfc.nasa.gov/", type: "text/html",