Skip to content

Instantly share code, notes, and snippets.

@miguelmota
miguelmota / nodejs-directory-structure.md
Last active December 2, 2023 08:47
Node.js MVC directory structure example.
Node.js MVC directory structure example.
├── app
│   ├── controllers
│   │   ├── admin
│   │   │   ├── posts.js
│   │   │   └── users.js
│   │   ├── posts.js
│ │ ├── session.js
@miguelmota
miguelmota / .bashrc
Created December 3, 2013 19:13
Show host IP address on your bash prompt.
# Show host IP address on your bash prompt.
#
# Example of prompt:
#
# moogs@192.168.1.100 : ~/Dropbox/workspace
# $
#
export PS1="\n\n\[\033[0;36m\]\u@$(ifconfig | grep "inet " | grep -v 127.0.0. | awk '{print $2}')\[\033[00m\]\[\033[0;32m\] : \w\[\033[00m\]\n\[\033[00;32m\]\$\[\033[00m\] "
export PS2="\[\033[0;32m\]>\[\033[00m\] "
@miguelmota
miguelmota / cache.appcache
Last active December 30, 2015 07:29
Application Cache example.
CACHE MANIFEST
# Revision 001 - 2013-12-01
OFFLINE:
/
# Cache resources as soon as they are downloaded.
CACHE:
/index.html
/favicon.ico
@miguelmota
miguelmota / bash
Last active December 30, 2015 08:08
Sass Compass source maps.
# Install latest Sass gem
sudo gem install compass --pre
# Install Compass sourcemaps gem
sudo gem install compass-sourcemaps --pre
# Run Compass as usual
compass watch
@miguelmota
miguelmota / gruntfile.js
Last active December 30, 2015 08:18
Uglify source maps with grunt.
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
sourceMap: '/js/main.min.js.map',
sourceMapRoot: '/',
sourceMappingURL: '/js/main.min.js.map',
sourceMapPrefix: 1,
@miguelmota
miguelmota / serialize.js
Last active December 30, 2015 21:29
Simple object serialization in JavaScript.
/* Simple object serialization
*
* Example:
* var obj = {foo: 'bar', baz: 'quz'};
* var querystring = serialize(obj);
*
* querystring value:
* foo=bar&baz=quz
*/
@miguelmota
miguelmota / getDates.js
Last active February 7, 2024 23:43
Get dates in between two dates with JavaScript.
// Returns an array of dates between the two dates
function getDates (startDate, endDate) {
const dates = []
let currentDate = startDate
const addDays = function (days) {
const date = new Date(this.valueOf())
date.setDate(date.getDate() + days)
return date
}
while (currentDate <= endDate) {
@miguelmota
miguelmota / collision.js
Last active December 31, 2015 07:38
Simple collision detection in JavaScript.
// Collision detection
// Returns true if one element overlaps the other
// Using jQuery
var collision = function($div1, $div2) {
var x1 = $div1.offset().left;
var y1 = $div1.offset().top;
var h1 = $div1.outerHeight(true);
var w1 = $div1.outerWidth(true);
var b1 = y1 + h1;
@miguelmota
miguelmota / gif.sh
Last active June 1, 2020 12:35
Convert a .MOV to an animated .GIF using FFMPEG and Gifsicle.
#!/bin/bash
# Convert a .MOV to an animated .GIF using FFMPEG and Gifsicle.
# Credit: https://gist.github.com/dergachev/4627207
#
# Dependencies:
# ffmpeg
# gifsicle
#
# Example:
@miguelmota
miguelmota / interfaces
Last active November 24, 2021 21:22
Raspberry Pi Raspbian OS wifi interface settings.
# vim /etc/network/interfaces
#
# it would be a good idea to update before:
#
# sudo apt-get update
# sudo apt-get upgrade
# sudo rpi-update
auto lo