Skip to content

Instantly share code, notes, and snippets.

View pyadav's full-sized avatar
🐢
learning new stuff

Praveen Yadav pyadav

🐢
learning new stuff
View GitHub Profile
async function func () {
const url = 'https://maps.googleapis.com/maps/api/geocode/json?address=94043&sensor=false';
const { results: [ result ] } = await fetch(url).then((response) => response.json());
return JSON.stringify(result, null, 2);
}
func().then(console.log.bind(console));
/*
var promisify = require("promisify-node");
function makeItAsync(callback) {
callback(null, true);
}
// Convert the function to return a Promise.
var wrap = promisify(makeItAsync);
// Invoke the newly wrapped function.
// promisify-node is necessary to turn node callback functions in Promises
let promisify = require("promisify-node");
let fs = promisify('fs');
let path = require('path');
let dir = '/home/jaydson.gomes/public_html';
async function statDir() {
// Asynchronous node fs.readdir return Promises
let list = await fs.readdir(dir);
@pyadav
pyadav / jquery.css3caching.js
Last active August 29, 2015 14:27 — forked from mdellanoce/jquery.css3caching.js
CSS3 caching
(function($) {
function parseImagesFromCSS(doc) {
var i, j,
rule,
image,
pattern = /url\((.*)\)/,
properties = ['background-image', '-webkit-border-image'],
images = {};
if (doc.styleSheets) {
@pyadav
pyadav / app.js
Last active August 29, 2015 14:27 — forked from mdellanoce/app.js
Auto-optimization with Express and RequireJS
var express = require('express'),
requirejs = require('requirejs'),
app = module.exports = express.createServer();
app.configure('development', function(){
// Use development version of static files
app.use(express.static(__dirname + '/public'));
});
app.configure('production', function(){
@pyadav
pyadav / .Ecmascript.
Last active August 29, 2015 14:27
Ecmascript features list
ES2015 (a.k.a. ES6)
- Lots of new language features
- Classes
- Arrow Functions
- Destructuring
- Let + Const
- Iterators
- Generators
- Modules
@pyadav
pyadav / BaseClass.jsx
Last active August 29, 2015 14:27 — forked from tmbtech/BaseClass.jsx
ES7 Decorator Test
import React from "react";
import {ContextTypes, DefaultProps, PropTypes} from "./Decorators";
// this will throw a warning.
@PropTypes({name: React.PropTypes.func})
@DefaultProps({name: "robbie"})
class BaseClass extends React.Component {
render() {
return (
<div className="base-class-example">
@pyadav
pyadav / some-component.js
Last active November 28, 2015 01:00 — forked from oriSomething/some-component.js
Reflux + React + ES7 decorators
import React, { Component } from 'react';
import storeDecorator from './store-decorator';
import someStore, { SOME_STORE_SYMBOL } from './some-reflux-store';
@storeDecorator(someStore)
class SomeComponent extends Component {
render() {
return (
<div>
{this.state[SOME_STORE_SYMBOL].someProperty}
@pyadav
pyadav / App-react-flux-async-dependent-store-init.js
Last active August 29, 2015 14:27 — forked from MadLittleMods/App-react-flux-async-dependent-store-init.js
Flux: Initialize from asynchronous storage with interdependent stores - `waitFor` async - The real solution to this problem would be to create a DAO/service to feed data into the store via actions.
import React from 'react';
import SomeStore from '../stores/SomeStore';
import AppActions from '../actions/AppActions';
function gatherSomeStoreState(props, state) {
return {
myRandomNumber: SomeStore.getRandomNumber()
};
}
@pyadav
pyadav / ReactJS-Cookie.js
Last active August 29, 2015 14:27 — forked from simondavies/ReactJS-Cookie.js
A React JS & ES2015 Cookies pop up component and example files