Skip to content

Instantly share code, notes, and snippets.

@husobee
husobee / digital_root.py
Last active Oct 3, 2016
submission for codewars.com digital root
View digital_root.py
def digital_root(n):
""" digital_root - recursively figure out the digital root of a number"""
s = 0 # s -> running sum
while n > 0:
# take each digit from the number by running mod 10 (ones position in base 10 number)
s += int(n%10)
# reduce the number by a factor of 10 to remove the ones position
n = int(n/10)
if s >= 10:
# if the num is greater than or equal to 10 recursively call self
@husobee
husobee / main.go
Created Oct 1, 2016
reverse a string
View main.go
package main
import (
"fmt"
)
func reverseStr(s string) string {
input := []byte(s)
for i := 0; i < len(input)/2; i++ {
input[i], input[(len(input)-1)-i] = input[(len(input)-1)-i], input[i]
@husobee
husobee / main.go
Created Oct 1, 2016
reverse an int (friend's interview question)
View main.go
package main
import (
"fmt"
)
func reverse(input int) int {
var result int
for ; input != 0; input = input / 10 {
result = input%10 + 10*result
@husobee
husobee / main.go
Last active May 18, 2016
handle signals golang
View main.go
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
@husobee
husobee / progress.sh
Last active Feb 24, 2021
fun beginnings of a bash progress bar
View progress.sh
#!/bin/bash
function progress {
cattail='='
cat1=' ,------, '
cat2=' | /\_/\ '
cat3=' |__( ^ .^) '
cat4=' "" "" '
echo;echo;echo;echo;echo;echo
@husobee
husobee / client_tls_info.go
Last active Dec 14, 2020
discovery of tls in go, and the handshake process
View client_tls_info.go
package main
import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
"net"
"net/http"
)
@husobee
husobee / nyan.c
Last active Jan 19, 2016
Exploring Ncurses in C with nyan cat
View nyan.c
#include <stdlib.h>
#include <ncurses.h>
#include <unistd.h>
/* our cat */
const char nyan_cat[4][12] = {
",------, \n",
"| /\\_/\\\n",
"|__( ^ .^) \n",
"\"\" \"\" \n"};
@husobee
husobee / validation-main.go
Created Jan 8, 2016
input validation sanely
View validation-main.go
package main
import (
"encoding/json"
"errors"
"net/http"
"github.com/asaskevich/govalidator"
)
@husobee
husobee / main.go
Created Dec 22, 2015
simple golang http middleware chaining example
View main.go
package main
import (
"fmt"
"net/http"
"time"
"golang.org/x/net/context"
"github.com/husobee/backdrop"
@husobee
husobee / main.go
Created Dec 9, 2015
bcrypt concurrency
View main.go
package main
import (
"flag"
"fmt"
"time"
"golang.org/x/crypto/bcrypt"
)