Skip to content

Instantly share code, notes, and snippets.

View calderaro's full-sized avatar

Angel Calderaro calderaro

  • Mexico City
View GitHub Profile
@calderaro
calderaro / app.js
Created June 2, 2017 18:20
fix selectionRange
function setElementData(element, name, value, oldValue) {
if (name === "key") {
} else if (name === "style") {
for (var i in merge(oldValue, (value = value || {}))) {
element.style[i] = value[i] || ""
}
} else {
var selectionStart = element.selectionStart
var selectionEnd = element.selectionEnd
@calderaro
calderaro / spriteRendering.JS
Created August 10, 2017 16:56
sprite rendering with speed control and rotation
bctx.save()
bctx.translate(500, 400);
bctx.rotate((frame * -5) * Math.PI / 180)
const animationSpeed = parseInt(frame / 2.7, 10)
bctx.drawImage(
images[0],
(images[0].width / 5) * (animationSpeed % 5), 0, // sprite width * animationSpeed % spriteLength
images[0].width / 5, images[0].height / 2,
(images[0].width / 5) / - 2, (images[0].height / 2) / -2,
images[0].width / 5, images[0].height / 2
@calderaro
calderaro / limitLoop.js
Created August 14, 2017 05:13 — forked from addyosmani/limitLoop.js
Limit the frame-rate being targeted with requestAnimationFrame
/*
limitLoop.js - limit the frame-rate when using requestAnimation frame
Released under an MIT license.
When to use it?
----------------
A consistent frame-rate can be better than a janky experience only
occasionally hitting 60fps. Use this trick to target a specific frame-
rate (e.g 30fps, 48fps) until browsers better tackle this problem
@calderaro
calderaro / app.js
Created September 11, 2017 02:58 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@calderaro
calderaro / deploy.js
Created August 20, 2018 16:49
deploy over http
const {exec} = require('child_process')
export default function runDeploy () {
return new Promise((resolve, reject) => {
exec('git pull origin master', (err, stdout1, stderr) => {
if (err) return reject(stderr)
exec('npm run update', (err, stdout2, stderr) => {
if (err) return reject(stderr)
return resolve([stdout1, stdout2])
})
@calderaro
calderaro / install-watchman.sh
Created January 18, 2019 01:22
how to install watchman ubuntu xD
sudo apt install -y autoconf automake build-essential python-dev libtool libssl-dev pkg-config
cd /tmp
git clone https://github.com/facebook/watchman.git
cd watchman/
git checkout v4.9.0
./autogen.sh
./configure
make
sudo make install
@calderaro
calderaro / graph-helpers.js
Created February 8, 2019 06:30
graph helper functions
const getBaseNumber = num => parseInt('1'.padEnd(String(num).length, '0'))
const roundNumber = num => Math.ceil(num / getBaseNumber(num)) * getBaseNumber(num)
const getNumberOfTicks = num => roundNumber(num) / getBaseNumber(num)
console.log(getBaseNumber(4500))
console.log(roundNumber(4800))
console.log('ticks: ', getNumberOfTicks(4500))
@calderaro
calderaro / localStorage.js
Created June 11, 2019 17:27
Redux local storage util
import omit from 'lodash/omit';
import throttle from 'lodash/throttle';
import pick from 'lodash/pick';
export const loadState = () => {
try {
const serialized = localStorage.getItem('store');
if (!serialized) return undefined;
@calderaro
calderaro / matterNotes1.html
Created July 19, 2019 17:43
Matterjs Notes 1
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/matter.js"></script>
</head>
<body>
<script>
// module aliases
const Engine = Matter.Engine;
const Render = Matter.Render;
const World = Matter.World;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://d3js.org/d3-array.v2.min.js"></script>
<script src="https://d3js.org/d3-color.v1.min.js"></script>
<script src="https://d3js.org/d3-format.v1.min.js"></script>