Skip to content

Instantly share code, notes, and snippets.

View henryhamon's full-sized avatar
🏠
Working from home

Henry Hamon henryhamon

🏠
Working from home
View GitHub Profile
@henryhamon
henryhamon / helper.go
Created October 25, 2017 12:39
GoLang helper
package helpers
import (
"crypto/rand"
"crypto/sha1"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"io"
@henryhamon
henryhamon / custom-tinycore.sh
Created June 28, 2017 16:59 — forked from dankrause/custom-tinycore.sh
Create a custom tinycore linux iso. Adjust the config at the beginning of the script, or supply a conf as the first arg. Requires xorriso.
#!/bin/bash
set -e
function cleanup() {
# clean up our temp folder
rm -rf "${TMPDIR}"
}
trap cleanup EXIT
@henryhamon
henryhamon / stringinslice.go
Created June 13, 2017 11:47
string in slice
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
@henryhamon
henryhamon / round.go
Created June 13, 2017 11:45
func to round
func Round(val float64, roundOn float64, places int) (newVal float64) {
var round float64
pow := math.Pow(10, float64(places))
digit := pow * val
_, div := math.Modf(digit)
if div >= roundOn {
round = math.Ceil(digit)
} else {
round = math.Floor(digit)
@henryhamon
henryhamon / rainbow.go
Last active June 13, 2017 11:13
Random color generator in Golang
package main
import (
"fmt"
"math"
)
func rainbow(numOfSteps, step float64) (int, int, int) {
var r, g, b float64
@henryhamon
henryhamon / c9-elixir.sh
Created May 12, 2017 19:25 — forked from padde/c9-elixir.sh
Install Script for Erlang/Elixir/Phoenix on Cloud9
#!/usr/bin/env bash
############### USAGE ###############
#
# 1. Create a new workspace on Cloud9 using the "Blank" template
#
# 2. Run this command in the console:
# bash <(curl -fsSL https://gist.githubusercontent.com/padde/3c6301f15cbd5025e131740dae33aa95/raw/c9-elixir.sh)
#
# 3. There is no step 3!
defmodule Sample1 do
# combining Enum functions
def find_indexes(collection, function) do
Enum.filter_map(Enum.with_index(collection), fn({x, _y}) -> function.(x) end, elem(&1, 1))
end
end
defmodule Sample2 do
# implementing as similar way as Enum.find_index
def find_indexes(collection, function) do
@henryhamon
henryhamon / group_cons.rb
Created February 28, 2017 20:23
Group Consecutive Numbers
arr = [1, 2, 3, 5, 7, 8, 9, 20, 21, 23, 29]
arr.inject([]) { |a,e| (a[-1] && e == a[-1][-1] + 1) ? a[-1] << e : a << [e]; a }
@henryhamon
henryhamon / Update remote repo
Created January 11, 2017 11:51 — forked from mandiwise/Update remote repo
Transfer repo from Bitbucket to Github
// Reference: http://www.blackdogfoundry.com/blog/moving-repository-from-bitbucket-to-github/
// See also: http://www.paulund.co.uk/change-url-of-git-repository
$ cd $HOME/Code/repo-directory
$ git remote rename origin bitbucket
$ git remote add origin https://github.com/mandiwise/awesome-new-repo.git
$ git push origin master
$ git remote rm bitbucket
/*************************************************
* This is a simple Monte Carlo simulation to see
* whether we should
* go for X BIG deal and/or Y SMALL deals.
*
* What is the best blend?
*
* Author: Ido Green | plus.google.com/+greenido
* Date: 16 July 2013
*