Skip to content

Instantly share code, notes, and snippets.

@serotta58
serotta58 / oneliners.js
Created April 2, 2019 06:39 — forked from mikowl/oneliners.js
👑 Awesome one-liners you might find useful while coding.
// By @coderitual
// https://twitter.com/coderitual/status/1112297299307384833
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// Type this in your code to break chrome debugger in that line.
@serotta58
serotta58 / index.html
Created March 14, 2019 05:10
Javascript click event for items on variable length list
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JavaScript Tests</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
@serotta58
serotta58 / exercise-loops-and-functions.go
Created March 5, 2019 05:19
Go tour exercise - Loops and Functions
package main
import (
"fmt"
"math"
)
// Use Newton's method to iterate square root solution
func Sqrt(x float64) float64 {
z := 1.0
@serotta58
serotta58 / exercise-slices.go
Created March 5, 2019 05:12
Go tour exercise - Slices
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
img := make([][]uint8, dy)
for y := range img {
img[y] = make([]uint8, dx)
for x := range img[y] {
img[y][x] = uint8( (x+y*6)/2 )
@serotta58
serotta58 / exercise-maps.go
Created March 5, 2019 05:10
Go tour exercise - Maps
package main
import (
"golang.org/x/tour/wc"
"strings"
)
// Return a map of the counts of each word in the string s
func WordCount(s string) map[string]int {
m := make(map[string]int)
@serotta58
serotta58 / exercise-fibonacci-closure.go
Last active March 5, 2019 05:44
Go tour exercise - Fibonacci closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
current := 0
next := 1
// On each call, return the next fibonacci number
@serotta58
serotta58 / exercise-stringer.go
Created March 5, 2019 04:43
Go tour exercise - Stringers
package main
import "fmt"
type IPAddr [4]byte
func (ip IPAddr) String() string {
return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
}
@serotta58
serotta58 / exercise-rot-reader.go
Created March 5, 2019 04:39
Go tour exercise - rot13Reader
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
@serotta58
serotta58 / exercise-equivalent-binary-trees.go
Created March 5, 2019 04:16
My solution to Go tour Equivalent Binary Trees exercise
package main
import (
"golang.org/x/tour/tree"
"fmt"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {