Skip to content

Instantly share code, notes, and snippets.

//----------------------------------
// Prototype Demo
// ---------------------------------
// Define functional object constructor called Quadrilateral
// with width and height as parameters.
var Quadrilateral = function(width, height) {
this.width = width;
this.height = height;
//
// Simple demonstration Call and Apply methods
//
// Square object with a color property and 2 methods
var square = {
color: "red",
getColor: function () {
return "I am the color " + this.color + "!";
@miguelmota
miguelmota / mixins.scss
Last active December 18, 2015 06:09
Some helper Sass mixins.
// Some helper Sass mixins
@mixin clear() {
&:before, &:after {
content: "";
display: block;
width: 100%;
height: 0;
overflow: hidden;
}
@miguelmota
miguelmota / slide-out-navigation.css
Last active April 28, 2022 00:10
A barebones slide out navigation using CSS3 translate. Blog post: http://www.miguelmota.com/slide-out-navigation-using-css3-translate/
/* Global styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
html, body {
height: 100%;
@miguelmota
miguelmota / audio.html
Last active December 19, 2015 10:49
Basic HTML5 Audio Manipulation. Blog post: http://www.miguelmota.com/blog/basic-html5-audio-manipulation/
<!-- Audio Control Buttons -->
<button id="play-button">Play</button>
<button id="stop-button">Stop</button>
<button id="pause-button">Pause</button>
<button id="loop-button">Loop</button>
<!-- Video element (live stream) -->
<label>Video Stream</label>
<video autoplay id="video" width="640" height="480"></video>
<!-- Canvas element (screenshot) -->
<label>Screenshot (base 64 dataURL)</label>
<canvas id="canvas" width="640" height="480"></canvas>
<!-- Capture button -->
<button id="capture-btn">Capture!</button>
@miguelmota
miguelmota / gruntfile.js
Last active December 23, 2015 10:08
A simple gruntfile boilerplate that I use for single page web apps.
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
express: {
all: {
options: {
port: 9000,
hostname: 'localhost',
@miguelmota
miguelmota / default
Last active January 30, 2023 02:28
Nginx + Node.js server configuration. Blog post: http://www.miguelmota.com/blog/nodejs-and-ngnix-on-ubuntu/
# The upstream module is the link between Node.js and Nginx.
# Upstream is used for proxying requests to other servers.
# All requests for / get distributed between any of the servers listed.
upstream helloworld {
# Set up multiple Node.js webservers for load balancing.
# max_fails refers to number of failed attempts
# before server is considered inactive.
# weight priorities traffic to server. Ex. weight=2 will recieve
# twice as much traffic as server with weight=1
server <your server ip>:3000 max_fails=0 fail_timeout=10s weight=1;
@miguelmota
miguelmota / memoization.js
Last active May 20, 2018 06:27
Memoization: caching function results in JavaScript. Blog post: http://www.miguelmota.com/blog/memoization-caching-function-results-in-javascript/
// Memoization technique.
// Try it. Open up the console on your browser and run:
// isPrime(5); // returns a boolean
// or someFunc('foo', 10); // returns an object
// The first time it will do the calculation and store the result,
// so next time you run isPrime(5) it will retrieve the result from
// the function's cache. The result is also stored in local storage
// so that it doesn't have to recalculate if you refresh the page.
// It'll retrieve the stored result from local storage.
@miguelmota
miguelmota / .bash_aliases
Last active October 2, 2018 12:14
Python SimpleHTTPServer alias for .bashrc
# Fires up a web server on localhost:8000
#
# Example:
#
# ~/workspace $ server
# Serving HTTP on 0.0.0.0 port 8000 ...
function server() {
local port="${1:-8000}"
open "http://localhost:${port}/"