Skip to content

Instantly share code, notes, and snippets.

@codexico
codexico / test.js
Created June 7, 2021 01:03
just a simple test runner
function logError(description, result, expectation) {
console.error('✖ ', description)
console.log('expected: ', expectation)
console.log('got: ', result)
}
function test(description, assertion, expectation) {
const result = assertion();
result === expectation
? console.log('✔ ', description)
@codexico
codexico / scroll.js
Created March 24, 2020 01:31
helper to animate scroll
let newAnimationId = 0;
export function animateScrollTo(el, to, duration) {
const init = el.scrollTop;
const startTime = performance.now();
let direction = to < init;
let change = 0;
if (direction) {
@codexico
codexico / javascript.json
Created March 18, 2020 00:34
vscode snippets for console.log
{
"Print object to console with label": {
"prefix": "cob",
"body": [
"console.log(\"${1:this} = \", ${1:this});",
"$0"
],
"description": "Log object to console"
},
"Print string to console": {
@codexico
codexico / executeOrRetry.js
Created May 13, 2019 22:21
retry function N times with condition in javascript
function executeOrRetry(retries, condition, fn, interval) {
if ((retries > 0) && condition()) {
setTimeout(() => {
executeOrRetry(retries--, condition, fn);
}, interval);
} else {
fn();
}
}
@codexico
codexico / capitalize.js
Created February 28, 2019 23:27
function to capitalize text
// string.js
export const capitalize = (string = '') =>
(typeof string === 'string' && string.substring(1))
? string[0].toUpperCase() + string.substring(1).toLowerCase()
: '';
// string.test.js
import { capitalize } from './string';
emailRegex = /^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,20})$/i;
@codexico
codexico / install_cocos2d-x.sh
Last active April 27, 2024 20:25
install cocos on ubuntu 16.04
sudo apt-get update
sudo apt-get upgrade
# 1) Download from source, the zip from the site has problems on linux
# https://github.com/cocos2d/cocos2d-x/pull/15958#issuecomment-228919359
git clone https://github.com/cocos2d/cocos2d-x.git
cd cocos2d-x
# 2016-06-27 branch master is broken, change to commit 04d3550
git checkout 04d3550
@codexico
codexico / pre-push
Last active June 2, 2023 12:08
hook to force tests and prevent failing pushs to develop or master
#!/usr/bin/env bash
# .git/hooks/pre-push
# hook to force tests and prevent failing pushs to develop or master
#
# Refs:
# http://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
# http://blog.ittybittyapps.com/blog/2013/09/03/git-pre-push/
#
# Bypassing the pre-push hook:
@codexico
codexico / .gitconfig
Last active November 23, 2022 10:17
git alias
# https://gist.github.com/codexico/2a34c0d599f3af93b46f
[color]
# Use colors in Git commands that are capable of colored output when
# outputting to the terminal. (This is the default setting in Git ≥ 1.8.4.)
ui = auto
[color "branch"]
-webkit-transform: translate3d(0, 0, 0);
-webkit-filter: blur(30px);
-moz-filter: blur(30px);
-o-filter: blur(30px);
-ms-filter: blur(30px);
filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='60');