Skip to content

Instantly share code, notes, and snippets.

View pavelpatrin's full-sized avatar

Pavel Patrin pavelpatrin

View GitHub Profile

A metatable can be defined like

local t = setmetatable({}, {
  __tostring = function() return 'custom tostring behavior!' end
})

Here are the metamethods that you can define, and their behavior

Operators

@basp1
basp1 / FindAllPaths.cs
Last active November 3, 2020 01:41
Find all paths between 2 graph nodes (iterative depth first search)
using System;
using System.Collections.Generic;
namespace CircuitSelector
{
public static class Graph
{
// use LinkedHashSet from http://stackoverflow.com/a/31419199/1312837 with some additions
public static List<List<int>> FindAllPaths(AdjacentMatrix adj, int begin, int end)
{
@jarun
jarun / infinality settings
Last active June 15, 2020 22:01
infinality-settings.sh
##################################################################
### INFINALITY ENVIRONMENT VARIABLES FOR EXTRA RUN-TIME OPTIONS ##
##################################################################
#
# These environment variables require that their respective patches
# from http://www.infinality.net have been applied to the Freetype
# installation you are using. They will do abolutely
# nothing otherwise!
#
# Thanks to this post:
# http://blog.ikato.com/post/15675823000/how-to-install-consolas-font-on-mac-os-x
$ brew install cabextract
$ cd ~/Downloads
$ mkdir consolas
$ cd consolas
$ curl -O http://download.microsoft.com/download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26/PowerPointViewer.exe
$ cabextract PowerPointViewer.exe
$ cabextract ppviewer.cab
@jboner
jboner / latency.txt
Last active November 15, 2024 14:00
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
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
@senko
senko / onchange.sh
Last active July 14, 2023 07:54
OnChange - Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <[email protected]>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of