Skip to content

Instantly share code, notes, and snippets.

@lucnap
lucnap / designer.html
Created June 17, 2015 09:21
designer
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../paper-item/paper-item.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@lucnap
lucnap / gist:dcd9454a639e1ea29a2a
Created February 19, 2016 09:20
Check if a javascript object is empty
function isObjectEmpty(obj) {
return Object.keys(obj).length === 0;
}
@lucnap
lucnap / async-parallel-with-arguments.js
Last active May 3, 2016 16:29
Javascript Nodejs execute function in async parallel with arguments
/*
the trick is in function.bind(null, args ...)
The functions will be executed independently but the results will be returned all togheter
in the array in the same order the functions were called
*/
var async = require("async");
function fn1(paramA, paramB, paramC, callback) {
setTimeout(function(){
var ret = '(' + paramA + ' ' + paramB + ' ' + paramC + ')';
@lucnap
lucnap / async-waterfall.js
Last active May 3, 2016 17:00
Javascript Nodejs async execution with waterfall method
/*
With async.waterfall the functions are executed one after the other and the result of each one is used
to call the next function.
fn0 -> fn1(resultFromfn0, callback) -> fn2(resultFromfn1, callback) -> fn3(resultFromfn2, callback)
*/
var async = require("async");
function fn0(myParam, callback) {
setTimeout(function(){
if (myParam === "ciao") {
@lucnap
lucnap / recursive-async-data-collect.js
Last active May 4, 2016 08:55
Javascript Nodejs recursive async call function for data collection from a remote source
/*
the example find data from facebook api search endpoint
*/
var findPages = function($center, $limit, $offset, callback) {
FB.api("/search", {q: "", type: "place", center: $center, distance: "15000", limit: $limit, offset: $offset, access_token: access_token}, function(result) {
callback(result);
});
};
@lucnap
lucnap / fb-page-access-token-no-expire
Last active October 22, 2021 09:53
How to get a Facebook Page Access Token that doesn't expire Never!
How to get a Facebook Page Access Token that doesn't expire Never!
- Go to http://developers.facebook.com/tools/explorer/
- Get a User Access Token with a permission "manage_pages"
- Convert this short-lived access token into a long-lived one by making this Graph API call:
https://graph.facebook.com/v2.6/oauth/access_token?client_id=<your FB App ID >&client_secret=<your FB App secret>&grant_type=fb_exchange_token&fb_exchange_token=<your short-lived access token>
- Make a call Graph API:
https://graph.facebook.com/v2.6/<your personal account FB user id>/accounts?access_token=<your long-lived access token>
- The returned access_token has no expiration unless you change your password or not more admin of the target page or deauthorize FB page
@lucnap
lucnap / gist:ee8ea073d6aa6757c4f7543c1aabd579
Created May 9, 2016 07:29
Create a self signed certificate for code signing on windows
http://stackoverflow.com/questions/84847/how-do-i-create-a-self-signed-certificate-for-code-signing-on-windows
@lucnap
lucnap / gist:d7f8d8699c82d50714da2d0cd6c8c9ff
Created May 9, 2016 10:55
WINDOWS XP PROFESSIONAL SP2 PRODUCT KEY
Professional SP2 VOL CCMWP-99T99-KCY96-FGKBW-F9WJT
@lucnap
lucnap / gist:96844fedfcd6e89b90513c10f4dbf3dc
Created May 11, 2016 16:04
Angular and Jquery interoperability
////////////////// from angular to jquery
// in angular controller
$scope.execFn1 = function() {
document.dispatchEvent(new CustomEvent( 'testEvent1',
{
detail: {mydata1: 'hello from angular'}
}
)
);
@lucnap
lucnap / conversione.js
Created November 4, 2016 07:44
nodejs sqlite mysql create table select
var sqlite3 = require("sqlite3").verbose();
var db = new sqlite3.Database('database/pagine.sqlite3');
var async = require("async");
var deasync = require("deasync");
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',