Skip to content

Instantly share code, notes, and snippets.

View barbagrigia's full-sized avatar

Vlad Trukhin barbagrigia

View GitHub Profile
@barbagrigia
barbagrigia / app.js
Created April 12, 2022 10:41 — forked from sochix/app.js
Proper way to measure request duration in a Node.js + Express application
const app = require('express')()
const getDurationInMilliseconds = (start) => {
const NS_PER_SEC = 1e9
const NS_TO_MS = 1e6
const diff = process.hrtime(start)
return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS
}
#!/bin/sh
echo "NVRAM and KEXT Cache Cleanup"
sudo nvram -c
sudo purge
sync

Algorithmic layouts

You are looking at the most important, and most abundant thing on the web. You can't see it, unfortunately, because it's very small… aaaaand it's invisible — so having a magnifying glass doesn't really help here. But still.

I'm talking, of course, about U+0020; not to be confused with the band U2, who are just as ubiquitous, but far less useful.

This unicode point, representing the humble space character, is between every word, in every run of text, on every page of the web. And it has a very special characteristic: it's not sticky like glue. If two words are neighbors but there's not enough room for both of them, the space will free the second word to wrap around and start a new line.

Before getting into flexible containers, viewport meta tags, and @media breakpoints this humble character is what makes the web fundamentally 'responsive'. That is: able to change the layout of its content to suit different devices, contexts, and settings. Browser text does this automa

@barbagrigia
barbagrigia / nes.py
Created May 20, 2020 09:08 — forked from karpathy/nes.py
Natural Evolution Strategies (NES) toy example that optimizes a quadratic function
"""
A bare bones examples of optimizing a black-box function (f) using
Natural Evolution Strategies (NES), where the parameter distribution is a
gaussian of fixed standard deviation.
"""
import numpy as np
np.random.seed(0)
# the function we want to optimize
@barbagrigia
barbagrigia / pg-pong.py
Created May 20, 2020 09:07 — forked from karpathy/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@barbagrigia
barbagrigia / gist:789f2d80e76e2f56d9be791b5d440dec
Created March 14, 2019 13:18 — forked from alphazo/gist:3303282
Clone MiFare cards using chinesse UUID writable cards

libnfc supports UUID writable cards and even has some dedicated tools for them.

However it doesn't work with some of the cards found on eBay that are even simpler to use. Sector 0 is unlocked and can be written without any additional commands. libnfc requires a small patch to get it working.

Following has been tested under ArchLinux with modified libnfc 1.5.1, mfoc 0.10.2 and a SCL3711 dongle.

Patch & recompile libnfc

The patch is fairly simple, open libnfc-1.5.1/utils/nfc-mfclassic.c and comment 2 lines (it was lines 384 and 385 for me):

// Try to write the trailer

@barbagrigia
barbagrigia / es6.json
Created February 21, 2019 11:20 — forked from mfd/arg.json
jwplayer
{
"description": "ES6 for Everyone — The best way to learn modern ES6 JavaScript.",
"title": "ES6",
"feedid": "ES6",
"kind": "DYNAMIC",
"playlist": [
{
"mediaid": "ES6_01",
"feedid": "ES6",
"image": "https://coursehunters.net/uploads/course_posters_/es6-for-everyone.jpg",
@barbagrigia
barbagrigia / graphik.md
Created February 21, 2019 11:15 — forked from mfd/ graphik.md
Graphik LCG font
https://cdn.rawgit.com/mfd/e7842774e037edf15919037594a79b2b/raw/665bdfc532094318449f1010323c84013d5af953/graphik.css

<link rel="stylesheet prefetch" href="https://cdn.rawgit.com/mfd/e7842774e037edf15919037594a79b2b/raw/665bdfc532094318449f1010323c84013d5af953/graphik.css">

@barbagrigia
barbagrigia / Title.js
Created December 27, 2018 21:54 — forked from theKashey/Title.js
Set document title from react node
class Title extends React.PureComponent {
domNode = document.createElement('div');
// ^ it's not added to the document
componentDidMount() {
this.componentDidUpdate();
}
componentDidUpdate() {
document.title = this.domNode.textContent || ':(';
@barbagrigia
barbagrigia / glam-for-css-folks.md
Created December 16, 2018 21:16 — forked from threepointone/glam-for-css-folks.md
why css purists will love glam

I made a little styling lib called glam

(some features are in development)

one

let's start off with the simplest use case. we'll make an 'index.html' page, and assume we've setup our js bundler to output bundle.js