Skip to content

Instantly share code, notes, and snippets.

View fractalbach's full-sized avatar
💭
🎈

Chris Achenbach fractalbach

💭
🎈
View GitHub Profile
@fractalbach
fractalbach / drag-and-drop.sh
Created November 8, 2017 21:16
Custom Keyboard shortcut shell script, drag and drop mouse clicking with a keyboard key!
#!/bin/bash
# xinput --list to identify the different input devices availiable to you.
# xinput query-state [device] where the device is a keyboard. Returns all the keys' states.
# xdotool mousedown 1 automates holding down the left mouse click.
# xdotool mouseup 1 automates releasing the left mouse click.
# This program begins by checking if the keyboard button is pressed at the time of its execution.
# If the keyboard button is in the DOWN position, then "press down" the mouse left click.
# wait for a bit (but not too long!), and then check the keyboard position again.
@fractalbach
fractalbach / exampleServer.go
Last active August 3, 2018 23:21
example go server where paths that have no extensions are directed to "/index.html"
package main
import (
"os"
"flag"
"fmt"
"log"
"net/http"
"path"
)
@fractalbach
fractalbach / caps2ctrl.md
Last active August 10, 2018 12:01
Map Caps to Control using setxkbmap

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
@fractalbach
fractalbach / fib.py
Created October 23, 2018 21:38
Fibonacci number in closed form expression
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 / print-title.py
Created November 7, 2018 09:30
simple title printer that uses ascii box chars and maintains its width
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 / randNumNorm.js
Created November 28, 2018 08:20
javascript random number experiment
/*
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 / main.cpp
Created December 6, 2018 19:18
WeightedGraphCpp created by fractalbach - https://repl.it/@fractalbach/WeightedGraphCpp
#include <iostream>
#include <map>
#include <set>
/**
* WeightedGraph
*
* @tparam _Key: Type of key used to reference nodes.
*
*/
@fractalbach
fractalbach / main.cpp
Created December 6, 2018 19:18
WeightedGraphCpp created by fractalbach - https://repl.it/@fractalbach/WeightedGraphCpp
#include <iostream>
#include <map>
#include <set>
/**
* WeightedGraph
*
* @tparam _Key: Type of key used to reference nodes.
*
*/
@fractalbach
fractalbach / staircase.go
Created February 24, 2019 03:25
Staircase Problem
package main
import (
"fmt"
"math/big"
)
var memo = map[int]*big.Int{
0: big.NewInt(0),
1: big.NewInt(1),
@fractalbach
fractalbach / simple-trie.go
Created March 10, 2019 09:29
Simple Trie using hashmap in each node
package main
import (
"fmt"
)
type node struct {
terminal bool
m map[rune]*node
}