Skip to content

Instantly share code, notes, and snippets.

View luigimannoni's full-sized avatar
🕐
Waiting for the deploy

Luigi Mannoni luigimannoni

🕐
Waiting for the deploy
View GitHub Profile
@luigimannoni
luigimannoni / best-date-format.js
Created February 17, 2022 11:25
Best date format
const now = new Date();
const zodiac = (year) => {
switch ((year - 4) % 12) {
case 0: return 'Rat';
case 1: return 'Ox';
case 2: return 'Tiger';
case 3: return 'Rabbit';
case 4: return 'Dragon';
case 5: return 'Snake';
@luigimannoni
luigimannoni / power-resize.sh
Created March 31, 2020 15:17
Imagemagick Mogrify/Resize image to nearest power of two
#!/bin/bash
# Or add to ~/bash_aliases
magickpow2 () {
echo Running imagemagick nearest pow with extension "$1"
for file in $(find . -name "$1")
do echo processing "$file"
local powwidth=$(identify -format "%[fx:2^(floor(log(w)/log(2)))]" $file)
if [ -z $powwidth ]
then
function fullscreen() {
const doc = document;
const elm = doc.documentElement;
if (elm.requestFullscreen) {
(!doc.fullscreenElement ? elm.requestFullscreen() : doc.exitFullscreen())
} else if (elm.mozRequestFullScreen) {
(!doc.mozFullScreen ? elm.mozRequestFullScreen() : doc.mozCancelFullScreen())
} else if (elm.msRequestFullscreen) {
(!doc.msFullscreenElement ? elm.msRequestFullscreen() : doc.msExitFullscreen())
} else if (elm.webkitRequestFullscreen) {
@luigimannoni
luigimannoni / cheatsheet.md
Last active March 15, 2018 15:01 — forked from javierarques/protractorAPICheatsheet.md
Protractor API Cheatsheet
@luigimannoni
luigimannoni / modal.stack.js
Created November 14, 2015 11:24
Stacked Modals
// Global variable, we use this to store DOM objects.
var modalStack = [];
// My function to create/open my modals.
function openModal() {
var modalHTML = '<div id="modal-'+modalStack.length+'" class="modal"><button onclick="openModal()">Open modal '+(modalStack.length+1)+'</button></div>'; // I populate the modal with my stuff and assign it an ID containing the current stack size.
document.body.insertAdjacentHTML( 'beforeend', modalHTML ); // Add into the body
modalStack.push( document.getElementById('modal-'+modalStack.length) ); // And push my DOM object I just created into the array.
}
@luigimannoni
luigimannoni / index.jade
Created November 13, 2015 12:15
WebGL Starting base template
.collection
a.prev(href='http://codepen.io/luigimannoni/details/', target='_parent') ← Prev
a.next(href='http://codepen.io/luigimannoni/details/', target='_parent') Next →
@luigimannoni
luigimannoni / progress-bar.jade
Created November 13, 2015 12:09
Radial progress bars
div.quick-stats-single(data-name='{{ title }}')
svg(viewBox='-10 -10 220 220')
path(d='M200,100 C200,44.771525 155.228475,0 100,0 C44.771525,0 0,44.771525 0,100 C0,155.228475 44.771525,200 100,200 C155.228475,200 200,155.228475 200,100 Z')
svg(viewBox='-10 -10 220 220')
path(d='M200,100 C200,44.771525 155.228475,0 100,0 C44.771525,0 0,44.771525 0,100 C0,155.228475 44.771525,200 100,200 C155.228475,200 200,155.228475 200,100 Z' stroke-dashoffset='{{animationAmount}}')
span.quick-stats-number(count-to="{{ percent }}")
@luigimannoni
luigimannoni / angular.exclude.js
Last active November 12, 2015 09:35
ngRoute $routeProvider exclude paths.
/**
* Callback used on non-angular paths (the Drupal paths for example) This triggers simply triggers a refresh of the browser.
*
* @function redirect
* @param {string} skip Argument passed from ngRoute, not used
* @param {string} url Argument with the link
*/
var redirect = function(skip, url) {
window.location.href = url;
}
@luigimannoni
luigimannoni / hash.generator.js
Created November 12, 2015 09:29
Random Hash Generator
function generateRandomHash(_length) {
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, _length);
}
@luigimannoni
luigimannoni / angular-videosharing-embed.js
Created November 10, 2015 22:12
angular-videosharing-embed.js with Youtube Iframe API support (and custom controls)
angular.module('videosharing-embed', []);
angular.module('videosharing-embed').service('PlayerConfig', function () {
'use strict';
this.createInstance = function (init) {
//can use angular.copy, but I prefer this way so I can still add properties to the object
var PlayerConfig = function (init) {
this.type = init.type;
this.playerRegExp = init.playerRegExp;
this.timeRegExp = init.timeRegExp;