Skip to content

Instantly share code, notes, and snippets.

View Willovent's full-sized avatar

William Klein Willovent

View GitHub Profile
@Willovent
Willovent / cloudSettings
Last active January 10, 2019 16:58
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-01-10T16:58:40.846Z","extensionVersion":"v3.2.4"}
import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';
import { AppServerModuleNgFactory } from './aot/src/app/app.server.module.ngfactory';
import * as express from 'express';
import * as fs from 'fs';
enableProdMode();
const app = express();
@Willovent
Willovent / W.js
Last active September 26, 2015 13:27
The W lib (Mini JQuery with some underscore)
// Wilib: lightweigth JQuery clone with no ie support
// $ is replace by W
window.W = function(selector) {
if (selector[0] == '<' && selector[selector.length - 1] == '>') {
var elem = selector.replace('>', '').replace('<', '');
var node = document.createElement(elem);
wObject(node);
return node;
}
@Willovent
Willovent / postJSON.js
Created August 27, 2015 08:11
vanilla post ajax with promise
postJSON = function(url,data){
return new Promise(function(resolve,reject)
{
var req = new XMLHttpRequest();
req.open('POST', url, true);
req.onreadystatechange = function () {
if (req.readyState == 4) {
if(req.status == 200)
resolve(JSON.parse(req.responseText));
else
@Willovent
Willovent / select.js
Last active August 29, 2015 14:25
Array select usage : [{name : "William", age : 24}, {name : "Bertrand", age : 47}].select('age'); => return : [{age : 24}, {age : 47}] parameter can be a string or an Array of prop to select
/* Array select
usage : [{name : "William", age : 24}, {name : "Bertrand", age : 47}].select('age');
=> return : [{age : 24}, {age : 47}]
parameter can be a string or an Array of prop to select*/
Array.prototype.select = function(props){
var newArray = [];
this.forEach(function(e){
var newObj = {};
if(typeof(props) === "string")
@Willovent
Willovent / getJson.js
Last active November 17, 2020 19:54
ajax with promise Vanilla
getJSON = function(url,data){
return new Promise(function(resolve,reject)
{
var req = new XMLHttpRequest();
req.open('GET', url, true);
req.onreadystatechange = function () {
if (req.readyState == 4) {
if(req.status == 200)
resolve(JSON.parse(req.responseText));
else
@Willovent
Willovent / where.js
Last active February 25, 2017 18:32
Array whereusage : [{name : "William", age : 24}, {name : "Bertrand", age : 47}].where({age : 24}); => return : [{name : "William", age : 24}]
var where = function(data, predicate) {
var newArray = [];
data.forEach(function(e) {
var add = true;
for (pred in predicate) {
if (predicate[pred] != e[pred]) {
add = false;
break;
}
}