Skip to content

Instantly share code, notes, and snippets.

@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
emailRegex = /^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,20})$/i;
@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';
@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 / 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 / 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 / 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)