This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this code logs an array of "following-list" of any twitter account | |
// just provide that account's username / screen_name | |
// and use consumer key and consumer secret from your twitter app | |
console.clear() | |
let people = [] | |
const cKey = 'consumer key' | |
const cSecret = 'consumer secret' | |
const toBeEncoded = cKey + ':' + cSecret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.clear() | |
var storageObj = { | |
name: 'Neymar', | |
nationality: 'Brazilian' | |
} | |
var dataStr = | |
'data:text/json;charset=utf-8,' + | |
encodeURIComponent(JSON.stringify(storageObj, null, 2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var file = document.querySelector('#myFile') | |
file.addEventListener('change', handleFile) | |
function handleFile (e) { | |
var myFile = e.target.files[0] | |
var fileReader = new FileReader() | |
fileReader.onload = function (event) { | |
console.dir(event.target.result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var file = document.querySelector('#myFile') | |
file.addEventListener('change', handleFile) | |
function handleFile (e) { | |
var myFile = e.target.files[0] | |
var fileReader = new FileReader() | |
fileReader.onload = function (event) { | |
console.log(event.target.result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let d = document | |
let $ = (element, event, callback) => | |
d.querySelector(element).addEventListener(event, callback) | |
let handleClick = () => console.log('click handled !') | |
$('button', 'click', handleClick) | |
//-------------------------------------------------OR, | |
let d = document |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function test () { | |
return await Promise.all([resolveHello(), resolveHi()]) | |
} | |
function resolveHello () { | |
return new Promise(resolve => setTimeout(() => resolve('hello'), 5000)) | |
} | |
function resolveHi () { | |
return new Promise(resolve => setTimeout(() => resolve('hi'), 1000)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this piece of code transforms form data into json and returns it | |
// just call the function and provide the targetted form as a parameter | |
// if you don't have browser support for FormData API then to use this code | |
// you can attach a script tag <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script> | |
// or if you want to use this as a module then use babel-polyfill | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// writing my own event emitter module | |
class EE { | |
constructor () { | |
this.obj = {} | |
} | |
on (event, callback) { | |
this.obj[event] | |
? this.obj[event].push(callback) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// some node modules still don't return promise. | |
// no problem ! we can use util.promisify....Awesome!!! | |
const fs = require('fs') | |
const util = require('util') | |
let readFile = util.promisify(fs.readFile) | |
async function readContent(){ | |
let data = await readFile('sample.txt','utf8') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var element = document.querySelector('#move') | |
element.addEventListener('mousedown', mouseDown, false) | |
window.addEventListener('mouseup', mouseUp, false) | |
function mouseUp () { | |
window.removeEventListener('mousemove', move, true) | |
} | |
function mouseDown (e) { | |
window.addEventListener('mousemove', move, true) |
OlderNewer