Skip to content

Instantly share code, notes, and snippets.

@chardos
chardos / scroll
Created September 5, 2019 05:13
Smooth scrolling
const easeModifier = (t) => {
return t > 0.5 ? 4 * Math.pow(t - 1, 3) + 1 : 4 * Math.pow(t, 3);
}
const createPositionsArray = (numFrames, totalDistance, pagePosition) => {
return new Array(numFrames + 1).fill(null).map((x, i) => {
const progress = i / numFrames;
const incrementDistance = easeModifier(progress) * totalDistance;
return pagePosition + (incrementDistance);
@chardos
chardos / ReactTestUtils.test.js
Created June 19, 2019 02:41
react test utils
import React from 'react';
import ReactTestUtils, { act } from 'react-dom/test-utils';
import ReactDOM from 'react-dom';
import TestRenderer from 'react-test-renderer';
import { Pill } from 'seek-style-guide/react';
import SkillsForm from './SkillsForm';
const defaultProps = {
initialSkills: [],
onChange: () => {},
@chardos
chardos / lodash.csv
Last active March 21, 2019 12:41
Lodash bundle sizes
lodash (gzip) lodash-es (gzip) lodash.utility (gzip)
1 utility 1.2 0.61 0.92
3 utilities 6.74 6.03 3.57
5 utilities 6.76 6.03 3.77
10 utilities 8.2 6.81 7.15
15 utilities 13.97 12.59 14.3
20 utilities 14.33 12.89 18.82
# Swallow error output
npm run postrelease 2>/dev/null || echo "postrelease script"
# Basic if statements
if [ $1 -gt 100 ]
then
echo Hey that\'s a large number.
pwd
fi
package main
import "fmt"
type Rect struct {
width int
height int
}
func (r *Rect) PrintArea() string {
func (r rect) perim() float64 {
return 2*r.width + 2*r.height
}
// This means implementing perim on rect
func Atoi(s string) (int, error)
// (int, error) means its returning a tuple of type int, and error
package main
import "fmt"
func main() {
a := 10
b := &a // &a is the reference of a
c := a
fmt.Println(a, b, *b, c) // *b means the value this reference is pointing to (dereference the value)
// 10 0xc0000160a0 10 10
@chardos
chardos / slices.go
Last active January 23, 2019 23:31
package main
import "fmt"
func main() {
// make a slice, without starting length off 0
s := make([]string, 0)
// above is same as
// s := []string{}
// in github.com/chardos/leftpad/leftpad.go
package leftpad
import (
"strings"
"unicode/utf8"
)
// This variable name is lowercase, so it's package-visible