Skip to content

Instantly share code, notes, and snippets.

View zanonnicola's full-sized avatar
💭
I like Kotlin

Nicola Zanon zanonnicola

💭
I like Kotlin
View GitHub Profile
{
"hits": 400,
"page": 15,
"pagePrev": 1,
"pageNext": 3,
"pageCount": 17
}
@zanonnicola
zanonnicola / critical.js
Created November 4, 2014 10:18
Detecting Critical CSS For Above-the-Fold Content.
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@zanonnicola
zanonnicola / index.js
Last active April 25, 2017 14:57
Pagination Issue
const promiseWhile = (url, condition) => {
let nextUrl;
let counter = 0;
if (!nextUrl) {
nextUrl = url;
}
const list = [];
const fetchData = (list) => {
console.log(`Counter: ${counter++}`);
console.log(`Next Url: ${nextUrl}`);
{"data":[{"url":"https://www.ookiy.com/u-s-top-court-preserves-alabama-campaign-finance-curbs-reuters/","source":2,"created":1493042349,"user_id":124197757,"visible":1,"comments":"() ookiy.com/u-s-top-court-…\n#political #US #News #political #TaxDay #CountrySongAFilm #FirstTimeIHeard #FelizMartes #GeneralElection ...","social_feed_id":795777,"social_post_id":"856507810825330692","social_id":"twitter","phash":null,"height":630,"width":1200,"original_image":"https://www.ookiy.com/wp-content/uploads/2017/04/trump-administration-says-no-u-s-trading-partners-manipulate-currency-reuters.png","author":"{\"name\":\"ookiy_news\",\"link\":\"http://twitter.com/ookiy_news\",\"picture\":\"https://res-5.cloudinary.com/tint/image/twitter_name/c_fill,h_75,w_75/ookiy_news\",\"username\":\"ookiy_news\",\"fullname\":\"ookiy_news\"}","embed":"{\"type\":\"\"}","image":"https://res-4.cloudinary.com/tint/image/fetch/c_limit,f_auto,fl_lossy,w_300/https://www.ookiy.com/wp-content/uploads/2017/04/trump-administration-says-no-u-s-tradi
@zanonnicola
zanonnicola / PerformanceNavigationTiming.js
Created February 24, 2017 11:07
The following script shows how a developer can use the PerformanceNavigationTiming interface to obtain accurate timing data related to the navigation of the document:
function init() {
var navigationTiming = performance.getEntriesByType("navigation")[0];
if (window.console) {
console.log("Name: " + navigationTiming.name + "\n" +
"Entry Type: " + navigationTiming.entryType + "\n" +
"Start Time: " + navigationTiming.startTime + "\n" +
"Duration: " + navigationTiming.duration + "\n" +
"Unload: " + (navigationTiming.unloadEventEnd -
navigationTiming.unloadEventStart) + "\n" +
"Redirect: " + (navigationTiming.redirectEnd -
@zanonnicola
zanonnicola / pipe.js
Created February 6, 2017 10:53
Functions piping
const _pipe = (func1, func2) => (...args) => func2(func1(...args));
const pipe = (...funcs) => funcs.reduce(_pipe);
// const myFunc = pipe(add(), double(), triple());
// myFunc(2, 2);
@zanonnicola
zanonnicola / fakeRes.json
Last active January 24, 2017 18:55
Fake API response
{
"id": 2,
"messages": [
{
"attachment": {
"type": "image",
"payload": {
"url": "https://placeholdit.imgix.net/~text?txtsize=33&txt=500%C3%97500&w=500&h=500"
}
}
@zanonnicola
zanonnicola / botdata.json
Created January 12, 2017 14:59
Test data for Facebook Chatbot
{
"messages": [
{
"attachment": {
"type": "image",
"payload": {
"url": "https://petersapparel.parseapp.com/img/item101-thumb.png"
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Single-Column Responsive Email Template</title>
<style>
@media only screen and (min-device-width: 541px) {
.content {

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})