Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
🎈

Chris Achenbach fractalbach

💭
🎈
  • San Francisco Bay Area
View GitHub Profile
@fractalbach
fractalbach / URL2Number.py
Created Apr 25, 2019
Displays a URL as it's IP address in dot-decimal notation, binary, and decimal representations.
View URL2Number.py
"""
URL to Binary to Decimal
How it Works
1. Does a DNS lookup on the URL given.
2. Converts the 255.255.255.255 into 4 binary numbers
3. Appends each of the binary numbers together
4. Converts the appended binary number into a decimal.
@fractalbach
fractalbach / heap_snippet.go
Created Apr 23, 2019
Example of using golang gods package for a heap
View heap_snippet.go
package main
import (
"fmt"
"github.com/emirpasic/gods/trees/binaryheap"
)
type item struct {
data interface{}
priority int
@fractalbach
fractalbach / simple-trie.go
Created Mar 10, 2019
Simple Trie using hashmap in each node
View simple-trie.go
package main
import (
"fmt"
)
type node struct {
terminal bool
m map[rune]*node
}
@fractalbach
fractalbach / staircase.go
Created Feb 24, 2019
Staircase Problem
View staircase.go
package main
import (
"fmt"
"math/big"
)
var memo = map[int]*big.Int{
0: big.NewInt(0),
1: big.NewInt(1),
View main.cpp
#include <iostream>
#include <map>
#include <set>
/**
* WeightedGraph
*
* @tparam _Key: Type of key used to reference nodes.
*
*/
View main.cpp
#include <iostream>
#include <map>
#include <set>
/**
* WeightedGraph
*
* @tparam _Key: Type of key used to reference nodes.
*
*/
@fractalbach
fractalbach / randNumNorm.js
Created Nov 28, 2018
javascript random number experiment
View randNumNorm.js
/*
randintNorm returns an integer in [min, max] including min and max.
The distribution will be closer to a normal distribution because it adds
2 instances of Math.random() together, like rolling 2 dice and adding them together.
*/
const randintNorm = (min, max)=> {
min = Math.ceil(min);
max = Math.floor(max);
let r = (Math.random() + Math.random()) / 2;
return Math.floor(r * (max - min + 1)) + min;
@fractalbach
fractalbach / print-title.py
Created Nov 7, 2018
simple title printer that uses ascii box chars and maintains its width
View print-title.py
def title(s, L=70):
L = L - len(s) - 4
l1 = L // 2
l2 = L - l1
prefix = l1*'═' + '╡'
postfix = '╞' + l2*'═'
print(prefix, s, postfix)
@fractalbach
fractalbach / fib.py
Created Oct 23, 2018
Fibonacci number in closed form expression
View fib.py
import sys
import math
def fib(n):
a = (1 + 5**(1/2)) / 2
b = (1 - 5**(1/2)) / 2
return (a**n - b**n)/ 5**(1/2)
if len(sys.argv) is not 2:
@fractalbach
fractalbach / caps2ctrl.md
Last active Aug 10, 2018
Map Caps to Control using setxkbmap
View caps2ctrl.md

CAPS to Control

There's a bunch of ways to do this. On windows, I would just use AutoHotKey. On a linux distro, setxkbmap does the trick, but it is not as flexible.

The goal:

  1. remapping the capslock to control
  2. remap something else to toggle capslock
You can’t perform that action at this time.