Skip to content

Instantly share code, notes, and snippets.

@chunpin
chunpin / momtest.md
Created October 27, 2023 08:17 — forked from spartonia/momtest.md
Summary if The Mom Test book.

Mom Test Notes

Chapter 1: The mom test

Bad/Good Questions

Bad: "Do you think it;s a good idea?"
Fix: You might ask them to show you how they currently do their job. Talk about which parts they love and hate. Ask which other tools and
processes they tried before settling on this one. Are they actively searching for a replacement? If so, what’s the sticking point? If not, why not? Where are they losing money with their current tools? Is there a budget for better

@chunpin
chunpin / smoothScroll.js
Created July 7, 2020 22:01
smoothScroll with VanillaJavascript
// Ease functions : http://www.gizma.com/easing/
function smoothScroll(target, duration){
var target = document.querySelector(target);
var targetPosition = target.getBoundingClientRect().top;
var startPosition = window.pageYOffset;
var distance = targetPosition - startPosition;
var startTime = null;
function prettyPrintDate(ms) {
var units = [
{ms: 1000, label: 'second'},
{ms: 1000 * 60, label: 'minute'},
{ms: 1000 * 60 * 60 , label: 'hour'},
{ms: 1000 * 60 * 60 * 24, label: 'day'},
],
result,
i,
function prettyPrintDate(ms) {
var units = [
{ms: 1000, label: 'second'},
{ms: 1000 * 60, label: 'minute'},
{ms: 1000 * 60 * 60 , label: 'hour'},
{ms: 1000 * 60 * 60 * 24, label: 'day'},
],
result,
i,
@chunpin
chunpin / requestAnimationFramePolyfill.js
Created October 20, 2019 14:41
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@chunpin
chunpin / combinedReducers.js
Created October 6, 2019 14:10
javascript redux -- Implementing combinereducers from scratch
const combineReducers = (reducers) => {
return (state = {}, action) => {
return Object.keys(reducers).reduce(
(nextState, key) => {
nextState[key] = reducers[key](
state[key],
action
);
return nextState;
},
@chunpin
chunpin / reducer-composition-with-objects.js
Created October 6, 2019 07:41
"combineReducers" native code pattern
/*
* Open the console
* to see the state log.
* pay attension on function "todoApp" on ***line 56*** ,
* this function COMBINED the return state of "visibilityFilter" and "todos" functions *** line 47 and line 33 ***,
* this pattern is pretty much equivalent to "combineReducers" from Redux.
* Which means this pattern is pretty much the native code OF "combineReducers"
*/
@chunpin
chunpin / createStore.js
Created October 3, 2019 12:47
redux the createStore() function
const createStore = (reducer) => {
let state;
let listeners = [];
const getState = () => state;
const dispatch = (action) => {
state = reducer(state, action);
listeners.forEach(listener => listener());
};
@chunpin
chunpin / FileSizeCaculator.fusion
Created August 21, 2019 06:36
file size calculator
prototype(Creaton.Product:Utility.Asset.FileSizeCaculator) < prototype(Neos.Fusion:Component) {
asset = null
filesize = ${this.asset ? this.asset.resource.filesize : null}
byteUnits = ${[' B', ' kB', ' MB', ' GB', ' TB']}
roundUnits = ${[0, 0, 1, 2, 2]}
factor = 1024
threshold = 900
renderer = Neos.Fusion:Value {
@if.filesize = ${Type.isNumeric(props.filesize)}
@chunpin
chunpin / pubsub.js
Last active May 19, 2019 09:26 — forked from learncodeacademy/pubsub.js
Basic Javascript PubSub Pattern
//events - a super-basic Javascript (publish subscribe) pattern
//There are also a lot of more library with complex features, search for key word "Javascript Event Library"
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},