Skip to content

Instantly share code, notes, and snippets.

@Oppodelldog
Oppodelldog / all-combinations.js
Created August 17, 2015 07:52
Evaluate all possible combinations of array items
var arr = ["a","b","c","d","e","f","g","h","i","j"];
for(i = 0; i <= Math.pow(2,arr.length)-1; i++){
var mask = i;
console.log("-------------------------------------" + mask);
var combination = "";
for(y=0; y<arr.length; y++){
if((mask & Math.pow(2,y)) == Math.pow(2,y)) combination += " " + arr[y];
}
@Oppodelldog
Oppodelldog / go-rand-test.go
Created November 25, 2015 22:16
short test of randomgenerated, structured data,trying to create scope safe random numbers
package main
import (
"fmt"
"math/rand"
)
type OfferGenerator struct {
offers []Offer
}
type RoomGenerator struct {
@Oppodelldog
Oppodelldog / arduino_analog_send.c
Last active April 2, 2017 15:22
arduino uno - send analog input values via serial connection
int sensors[]{A0,A1,A2,A3,A4,A5};
void setup()
{
Serial.begin(9600);
}
void loop()
{
int numberOfSensors = sizeof(sensors)/sizeof(int);
@Oppodelldog
Oppodelldog / graceful-shutdown-sample.go
Last active September 2, 2020 22:22
golang - graceful shutdown sample
package main
import (
"time"
"syscall"
"sync"
"fmt"
"os"
"os/signal"
"context"
@Oppodelldog
Oppodelldog / just-exec.sh
Created September 8, 2018 08:22
quickfix for crappy terminal in docker container
stty rows 50 && stty cols 2500 && export PS1='\u@\h: ' bash
@Oppodelldog
Oppodelldog / boolfuck.go
Created March 10, 2019 23:28
boolfuck interpreter (codewars kata, SPOILER)
package kata
import (
"strings"
)
// Boolfuck entry point for codewars kata
func Boolfuck(code string, input string) string {
return NewBookFuckInterpreter().Run(code, input)
}
@Oppodelldog
Oppodelldog / inner.sh
Created November 27, 2019 20:29
shell - nested traps
#!/bin/bash
err_report() {
echo "error in inner script: $(caller):$1"
}
trap 'err_report $LINENO' ERR
echo "INNER SCRIPT"
@Oppodelldog
Oppodelldog / logAccessInfo.go
Last active January 23, 2020 22:04
When staring a server on all interfaces, log hints of how to access it easily. Nice to have in development of the app
func logAccessInfo(addr string, port int, path, protocol string) {
ifaces, err := net.Interfaces()
if err != nil {
logrus.Infof("access it via %s://%s%s", protocol, addr, path)
}
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
continue
}
@Oppodelldog
Oppodelldog / portcheck.go
Created January 31, 2020 21:57
port check
package main
import (
"fmt"
"net"
"time"
)
func main() {
@Oppodelldog
Oppodelldog / waveshare_keys.go
Last active March 25, 2020 23:43
accessing keys of waveshare epaper 2.7 using github.com/stianeikeland/go-rpio/v4 in a convenient way
package main
import (
"fmt"
"github.com/stianeikeland/go-rpio/v4"
"log"
"time"
)
// Key defines a type for keys