Skip to content

Instantly share code, notes, and snippets.

View LucaColonnello's full-sized avatar
👋
Come say hello on Twitter!

Luca Colonnello LucaColonnello

👋
Come say hello on Twitter!
View GitHub Profile
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
if (!document.querySelectorAll) {
document.querySelectorAll = function(selector) {
var doc = document,
head = doc.documentElement.firstChild,
styleTag = doc.createElement('STYLE');
head.appendChild(styleTag);
doc.__qsaels = [];
styleTag.styleSheet.cssText = selector + "{x:expression(document.__qsaels.push(this))}";
window.scrollBy(0, 0);
@LucaColonnello
LucaColonnello / base-device-font-size.js
Last active August 29, 2015 14:08
Calculate base font size
// device base font size
window.getDeviceBaseFontSize = function( ) {
// check getted yet
if( !window.__baseDeviceFontSize ) {
window.__baseDeviceFontSize = 0;
var iframe = document.createElement( "IFRAME" );
iframe.style.display = "none";
document.body.appendChild( iframe );
var s = "<html><body><"+"/body><"+"/html>";
@LucaColonnello
LucaColonnello / element-em-size.js
Created October 30, 2014 10:28
Get Element EM Size
function getEmSize(el) {
return Number(getComputedStyle(el, "").fontSize.match(/(\d+(\.\d*)?)px/)[1]);
}
//PhantomJS http://phantomjs.org/ based web crawler Anton Ivanov anton.al.ivanov@gmail.com 2012
//UPDATE: This gist has been made into a Node.js module and now can be installed with "npm install js-crawler"
//the Node.js version does not use Phantom.JS, but the API available to the client is similar to the present gist
(function(host) {
function Crawler() {
this.visitedURLs = {};
};
module.exports = {
entry: './src/main',
module: {
loaders: [
// Transpile any JavaScript file:
{
test: /\.js$/,
loader: 'webpack-traceur?runtime',
exclude: /node_modules/ // <<<<===== prevent traceur to modify all from node_modules
}
@LucaColonnello
LucaColonnello / Google Maps Offset Center
Last active June 23, 2016 10:16
Google Maps Offset Center
// http://stackoverflow.com/questions/10656743/how-to-offset-the-center-point-in-google-maps-api-v3
function offsetCenter(map, latlng, offsetx, offsety) {
// latlng is the apparent centre-point
// offsetx is the distance you want that point to move to the right, in pixels
// offsety is the distance you want that point to move upwards, in pixels
// offset can be negative
// offsetx and offsety are both optional
var scale = Math.pow(2, map.getZoom());
@LucaColonnello
LucaColonnello / EventSimulator.js
Created June 8, 2015 08:09
Javascript Event Simulator
// http://stackoverflow.com/questions/6157929/how-to-simulate-a-mouse-click-using-javascript
function simulate(element, eventName)
{
var options = extend(defaultOptions, arguments[2] || {});
var oEvent, eventType = null;
for (var name in eventMatchers)
{
if (eventMatchers[name].test(eventName)) { eventType = name; break; }

Less generator mixin by type

Define a generator mixin which use some attributes differents by type. You can use the mixins passing the type you want. Then the mixins generate the attributes for the received type. This simulate a settings object.

A Pen by Luca Colonnello on CodePen.

License.

@LucaColonnello
LucaColonnello / React contentEditable component.js
Created June 11, 2015 12:37
React contentEditable with event
// http://jsfiddle.net/kb3gN/11378/
// http://stackoverflow.com/questions/22677931/react-js-onchange-event-for-contenteditable/27255103#27255103
// content editable component
var ContentEditable = React.createClass({
render: function(){
return <div id="contenteditable"
onInput={this.emitChange}
onBlur={this.emitChange}
contentEditable