Skip to content

Instantly share code, notes, and snippets.

View humamfauzi's full-sized avatar
💭
Wandering Around

Humam Fauzi humamfauzi

💭
Wandering Around
View GitHub Profile
@humamfauzi
humamfauzi / approx_distribution.py
Created July 20, 2018 06:25
Approximating distribution in an array.
import numpy as np
def approx_distribution(array):
array = np.array(array)
array.sort()
radii = np.std(array)
array_size = len(array)
max_val = np.max(array)
min_val = np.min(array)
container = np.zeros(array_size)
@humamfauzi
humamfauzi / threedots.go
Created August 8, 2018 05:41
Example using triple dots (variadic parameter) in Golang
package main
import "fmt"
// If function want to take any dtype, use interface{}. We can iterate it using for range
func threeDotsInterface(a ...interface{}) {
for k, v := range a {
fmt.Println("Key ", k, " Value ", v)
}
}
@humamfauzi
humamfauzi / routineComparison.go
Created August 8, 2018 11:41
Comparing ordinary routine and goroutine execution speed
package main
import (
"math/rand"
"time"
"log"
)
func randomArray(n int) []int {
array := make([]int, n)
@humamfauzi
humamfauzi / fanin.go
Last active August 9, 2018 12:00
Example of Using Fan In design pattern
package main
// Merge function is based from https://github.com/tmrts/go-patterns with little modification
import (
"sync"
"fmt"
"math/rand"
)
@humamfauzi
humamfauzi / builder.go
Created August 10, 2018 10:11
Builder pattern in Golang
package car
import "fmt"
type Speed float64
const (
MPH Speed = 1
KPH Speed = 1.60934
)
@humamfauzi
humamfauzi / pointer.go
Last active August 10, 2018 13:24
Note in Go Pointers
package main
import "fmt"
func main() {
var address0 *int
var number int
number = 32
address0 = &number
fmt.Println("Address ::", address0, "Value", number)
@humamfauzi
humamfauzi / Waitgroup_Explanation.md
Last active August 13, 2018 07:46
Basic Usage of WaitGroup

This is example how wait group works. Main objective of wait group is control concurrency. In vanilla.go, we have ordinary program without concurrency. The goal of each program is creating numbers of random integer, count total numbers of each numbers and print it with its ratios respective to total numbers created.

When we apply go goroutine, Go does not wait for the process to complete to proceed (non-blocking). While it is a good thing for execution speed, non-blocking process can be messed up as in no_waitgroup. Here come the wait group. Wait group have three methods which is .Add(), .Done(), Wait(). The first we use .Add() with input of how many process must be done before waiting is over. .Done() is a way telling the wait group that a process has been done. .Wait() halt the process unless all process done which indicated by number of .Done() executed is equal to .Add() input.

@humamfauzi
humamfauzi / randomChoice.go
Created August 13, 2018 09:53
Creating a Random Choice with weight in Golang
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func main() {
@humamfauzi
humamfauzi / main.py
Created August 21, 2018 12:21
Using Generated Data and Ensemble Learning in Python sklearn
# Please use Jupyter notebook to test this.
from sklearn.datasets import samples_generator
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import AdaBoostClassifier, BaggingClassifier, VotingClassifier
from sklearn.model_selection import StratifiedKFold, GridSearchCV, train_test_split
import numpy as np
import pandas as pd
X, y = samples_generator.make_classification(n_samples = 5000,
@humamfauzi
humamfauzi / datasciencetool.py
Last active September 6, 2018 12:39
My personal data science tool
def describe_dataframe(dataframe):
# Create a dictionary which have every detected categorical value counts in a dataframe and NaN ratio
describe_df = {}
for j in dataframe.dtypes.value_counts().index:
describe_dict = {}
cols = dataframe.select_dtypes(str(j)).columns
for i in cols:
if dataframe[i].nunique() < 100:
describe_dict[str(i)] = {"total_category": dict(dataframe[i].value_counts()),
"NaN_ratio": dataframe[i].isnull().sum()/float(dataframe.shape[0])}