Skip to content

Instantly share code, notes, and snippets.

View rbartoli's full-sized avatar

Riccardo Bartoli rbartoli

View GitHub Profile
@westc
westc / Cosine, Sine, and Tangent - Degrees.js
Created March 20, 2015 20:18
Versions of Math.cos, Math.sin, and Math.tan that accept values in degrees instead of radians.
(function (R) {
Math.cosd = function(d) { return Math.cos(d * R); };
Math.sind = function(d) { return Math.sin(d * R); };
Math.tand = function(d) { return Math.tan(d * R); };
})(Math.PI / 180);
@addyosmani
addyosmani / pubsub.js
Created December 5, 2012 16:04
Pub/Sub latest
/*
A basic implementation of the Publisher/Subscriber design pattern.
Developed by @addyosmani and @integralist
Example Usage:
// Create subscriber function to be called when topic publishes an event
var testSubscriber = function (topics, data) {
console.log(topics + ': ' + data);
};
@AllThingsSmitty
AllThingsSmitty / css-not.scss
Last active November 28, 2018 16:16
Use CSS :not() instead of applying and unapplying borders on navigations
.nav-tab {
...
// instead of putting it on
border-right: 1px solid #424242;
&:last-child {
border-right: 0; // and then taking it off
}
// use CSS not() to only apply to the elements you want
&:not(:last-child) {
border-right: 1px solid #424242;
@Coeur
Coeur / README.md
Last active October 18, 2020 21:41 — forked from lopezjurip/README.md
Write to NTFS on OSX Yosemite and El Capitan

Install osxfuse (3.x.x) from https://github.com/osxfuse/osxfuse/releases.

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Update Homebrew formulae:

brew update
@PaulKinlan
PaulKinlan / detect.js
Created March 5, 2015 16:29
Detect unknown content injection
var detectInjection = function(knownHostsArray) {
var requests = window.performance.getEntriesByType("resource");
var unknownHosts = [];
var knownHosts = {};
var foundHosts = {};
for (var knownHost in knownHostsArray) {
knownHosts[knownHostsArray[knownHost]] = true;
}
@getify
getify / step1.js
Last active February 28, 2022 16:38
transducing in javascript
function add1(v) { return v + 1; }
function isOdd(v) { return v % 2 == 1; }
function sum(total,v) { return total + v; }
var list = [2,5,8,11,14,17,20];
list
.map( add1 )
.filter( isOdd )
.reduce( sum );
@qrush
qrush / Inconsolata-dz-Powerline.otf
Created January 11, 2012 16:50
vim-powerline patched fonts
@colintoh
colintoh / douchebag-vertical-align.css
Created October 27, 2014 07:08
douchebag way of vertical alignment
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
@Warry
Warry / Article.md
Created December 11, 2012 00:11
How to make faster scroll effects?

How to make faster scroll effects?

  • Avoid too many reflows (the browser to recalculate everything)
  • Use advanced CSS3 for graphic card rendering
  • Precalculate sizes and positions

Beware of reflows

The reflow appens as many times as there are frames per seconds. It recalculate all positions that change in order to diplay them. Basically, when you scroll you execute a function where you move things between two reflows. But there are functions that triggers reflows such as jQuery offset, scroll... So there are two things to take care about when you dynamically change objects in javascript to avoid too many reflows:

@joemccann
joemccann / nginx + node setup.md
Created October 25, 2010 02:06
Set up nginx as a reverse proxy to node.js.

The idea is to have nginx installed and node installed. I will extend this gist to include how to install those as well, but at the moment, the following assumes you have nginx 0.7.62 and node 0.2.3 installed on a Linux distro (I used Ubuntu).

In a nutshell,

  1. nginx is used to serve static files (css, js, images, etc.)
  2. node serves all the "dynamic" stuff.

So for example, www.foo.com request comes and your css, js, and images get served thru nginx while everything else (the request for say index.html or "/") gets served through node.

  1. nginx listens on port 80.