Skip to content

Instantly share code, notes, and snippets.

View calderaro's full-sized avatar

Angel Calderaro calderaro

View GitHub Profile
@calderaro
calderaro / static_server.js
Last active September 3, 2015 01:38 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
@calderaro
calderaro / index.html
Created March 3, 2016 20:54 — forked from anonymous/index.html
Services average // source http://jsbin.com/dekogepivu
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Services average</title>
</head>
<body>
<select id="service">
<option value="none">Select Service</option>
<option value="carpentry">Carpentry</option>
@calderaro
calderaro / LRC.java
Created April 2, 2016 01:03
Longitudinal Redundancy Check (LRC) calculator for a byte array.
public class LRC {
public static byte calculateLRC(byte[] bytes) {
byte LRC = 0;
for (int i = 0; i < bytes.length; i++) {
LRC ^= bytes[i];
}
return LRC;
}
}
@calderaro
calderaro / index.html
Created August 4, 2016 02:04 — forked from anonymous/index.html
JS Bin Coding Challenge #30: Phyllotaxis // source http://jsbin.com/hezidi
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Coding Challenge #30: Phyllotaxis">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
canvas {
border: black 1px solid;
@calderaro
calderaro / socket.io-emit-broadcast-usage.js
Created November 13, 2016 03:11 — forked from markogresak/socket.io-emit-broadcast-usage.js
Different destination groups for socket.io emit and broadcast functions
// send to current request socket client
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.sockets.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
canvas {
border: 1px solid black
}
@calderaro
calderaro / mp3.js
Created January 9, 2017 06:20 — forked from dtrce/mp3.js
streaming mp3 using nodejs
var http = require('http'),
fileSystem = require('fs'),
path = require('path')
util = require('util');
http.createServer(function(request, response) {
var filePath = 'path_to_file.mp3';
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {
@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 / fileHandler.ts
Created September 21, 2019 17:35 — forked from jasonbyrne/fileHandler.ts
Firebase Functions + Express file uploader handler
/* Firebase Functions messes with your request and will wreck your day because none of the
* traditional upload handlers with Express will work.
*
* Credit: https://stackoverflow.com/questions/47242340/how-to-perform-an-http-file-upload-using-express-on-cloud-functions-for-firebase
*/
const Busboy = require('busboy');
const allowedMethods: string[] = ['POST', 'PUT'];
export class FileUpload {