Skip to content

Instantly share code, notes, and snippets.

Paul Mucur mudge

Block or report user

Report or block mudge

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mudge
mudge / auto.sh
Created Aug 26, 2019
Auto-switch Node.js versions with chnode by reading .node-version files
View auto.sh
# Based off chruby's auto.sh: https://github.com/postmodern/chruby#auto-switching
unset NODE_AUTO_VERSION
function chnode_auto() {
local dir="$PWD/" version
until [[ -z "$dir" ]]; do
dir="${dir%/*}"
if { read -r version <"$dir/.node-version"; } 2>/dev/null || [[ -n "$version" ]]; then
@mudge
mudge / use-debounce.js
Last active Sep 22, 2019
A custom React Hook for a debounced click handler with a given callback and delay.
View use-debounce.js
/*
* Inspired by Dan Abramov's "Making setInterval Declarative with React Hooks",
* this is a custom hook for debouncing a callback (e.g. for click handlers) such
* that a callback will not be fired until some delay has passed since the last click.
* The callback will automatically be updated with the latest props and state on every
* render meaning that users don't need to worry about stale information being used.
*
* See https://overreacted.io/making-setinterval-declarative-with-react-hooks/ for the
* original inspiration.
*/
@mudge
mudge / README.md
Last active Jan 21, 2020
Compiling & installing cloudflared for DNS-over-HTTPS on a Raspberry Pi Model B
View README.md
@mudge
mudge / dijkstra_with_fibonacci_heap.rb
Last active Jul 15, 2018
Implementing Dijkstra's algorithm with Fibonacci Heap
View dijkstra_with_fibonacci_heap.rb
require 'fibonacci_heap'
# Assuming `graph` is an object with the following interface that stores vertices as `FibonacciHeap::Node`
# instances and `source` is a `FibonacciHeap::Node`:
#
# * `graph.vertices`: return an Enumerable of all vertices in the graph
# * `graph.neighbours(u)`: return an Enumerable of all vertices that neighbour a given vertex `u`
# * `graph.length(u, v)`: return the numeric weight of the edge between two given vertices `u` and `v`
def dijkstra(graph, source)
dist = Hash.new(Float::INFINITY)
@mudge
mudge / fibonacci_heap.rb
Last active Jun 24, 2018
A Ruby implementation of a Fibonacci heap
View fibonacci_heap.rb
class CircularDoublyLinkedList
include Enumerable
class Node
include Comparable
attr_accessor :key, :next, :prev
alias right next
alias left prev
@mudge
mudge / dijkstra.rb
Last active Jun 22, 2018
An implementation of Dijkstra's algorithm in Ruby
View dijkstra.rb
# A pure Ruby implementation of https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
#
# Takes a graph in hash form, e.g. { 'A' => ['B', 'C'], 'B' => ['D'], 'C' => ['D'] },
# and a source node, e.g. 'A', and returns the distances to every reachable node and a hash of "next hops" for each node.
def dijkstra(graph, source)
q = graph.keys
prev = {}
dist = Hash.new(Float::INFINITY)
dist[source] = 0
@mudge
mudge / snitch.rb
Last active Feb 17, 2018
A wrapper class for reporting on method calls useful for reverse engineering
View snitch.rb
# snitch = Snitch.new('A string')
#=> #<Snitch:0x00007fe53a1964b0 @obj="A string">
# snitch.empty?
# Calling empty? on A string with []
#=> false
class Snitch
attr_reader :obj
def initialize(obj)
@mudge
mudge / best_fit.rb
Last active Jul 28, 2017
Applying bin packing techniques to GNIP PowerTrack rules
View best_fit.rb
domains = ARGF.readlines.map(&:chomp)
queries = domains.map { |domain| %[url_contains:"/#{domain}" OR url_contains:".#{domain}"] }
queries.sort_by!(&:size)
rule_limit = 1024
operator_limit = 30
rules = [queries.pop]
queries.reverse_each do |query|
View arith.rs
enum Error {
NoRuleApplies,
}
enum Term {
TmTrue,
TmFalse,
TmIf(Box<Term>, Box<Term>, Box<Term>),
TmZero,
TmSucc(Box<Term>),
You can’t perform that action at this time.