Skip to content

Instantly share code, notes, and snippets.

View zainfathoni's full-sized avatar
:octocat:
Revamping www.zainfathoni.com

Zain Fathoni zainfathoni

:octocat:
Revamping www.zainfathoni.com
View GitHub Profile
@zainfathoni
zainfathoni / .gitignore
Created December 23, 2015 10:12 — forked from mahdi/.gitignore
A .gitignore file for a .NET developer
#Junk Files
*.DS_Store
[Tt]humbs.db
#Visual Studio Files
[Oo]bj
[Bb]in
[Dd]ebug
[Bb]uild/
*.user
@zainfathoni
zainfathoni / Object.assign.js
Created November 8, 2016 22:27 — forked from fabien-d/Object.assign.js
Nested Object.assign calls formatting
let object = {
key: {
subkey: 'value',
status: 'STATUS'
}
};
// compact
Object.assign( {}, object, { key: Object.assign( {}, object.key, { status: 'PENDING' } ) } );
@zainfathoni
zainfathoni / gist:a214f0df757a1d8ceff6d6402fa73c9b
Created April 8, 2017 09:33 — forked from abesto/gist:3476594
Go: Newton's method for square root
/*
A Tour of Go: page 44
http://tour.golang.org/#44
Exercise: Loops and Functions
As a simple way to play with functions and loops, implement the square root function using Newton's method.
In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating: z - (z*z - x) / (2 * z)
package main
import "golang.org/x/tour/pic"
func imageFunc(x, y int) uint8 {
return uint8(x) ^ uint8(y)
}
func Pic(dx, dy int) (image [][]uint8) {
image = make([][]uint8, dy)
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) (count map[string]int) {
words := strings.Fields(s)
count = make(map[string]int)
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b, n := 0, 1, 0 // a & b are the future values
return func() int {
n, a, b = a, b, a+b
package main
import "fmt"
type IPAddr [4]byte
// TODO: Add a "String() string" method to IPAddr.
func (ip IPAddr) String() string {
return fmt.Sprintf("%v.%v.%v.%v", ip[0], ip[1], ip[2], ip[3])
}
package main
import (
"fmt"
"math"
)
const DELTA = 0.00000000001
const INITIAL_Z = 100.0
package main
import (
"fmt"
"math"
)
const DELTA = 0.00000000001
const INITIAL_Z = 100.0
package main
import "golang.org/x/tour/reader"
type MyReader struct{}
func (r MyReader) Read(b []byte) (n int, err error) {
b[0] = 'A'
return 1, nil