Skip to content

Instantly share code, notes, and snippets.

View dhoko's full-sized avatar
💭
°˖✧◝(⁰▿⁰)◜✧˖°

dhoko dhoko

💭
°˖✧◝(⁰▿⁰)◜✧˖°
View GitHub Profile
@dhoko
dhoko / compute.js
Created September 30, 2015 14:42
Calcul total dépensé en billet de train sur Capitaine Train (Page billet)
Array.from($$('.folder__price-label'))
.map(item => item.textContent.split('€')[0].trim().replace(',', '.'))
.map(Number)
.reduce((accus, item) => accus + item, 0);
@dhoko
dhoko / countWatcher.js
Created September 22, 2015 09:42
[Bookmarklet] Debug AngularJS
// Version without jQuery
javascript:(function () { var root = angular.element(document.getElementsByTagName('body')); var watchers = []; var f = function (element) { angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) { if (element.data() && element.data().hasOwnProperty(scopeProperty)) { angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) { watchers.push(watcher); }); } }); angular.forEach(element.children(), function (childElement) { f(angular.element(childElement)); }); }; f(root); var watchersWithoutDuplicates = []; angular.forEach(watchers, function(item) { if(watchersWithoutDuplicates.indexOf(item) < 0) { watchersWithoutDuplicates.push(item); } }); console.log(watchersWithoutDuplicates.length); })();
// Version with jQuery
javascript:(function () { var root = $(document.getElementsByTagName('body')); var watchers = []; var f = function (element) { if (element.data().hasOwnProperty('$scope')) { angular.forEach(element.data().$scope.$$watchers, function (watche
@dhoko
dhoko / loop.sh
Created September 21, 2015 09:55
Loop {1..10}
cd /var/www
for i in $(seq 10)
do
echo Start monsite$i
forever start --uid=monsite$i -a monsite1path/monsite$i.js
done
@dhoko
dhoko / app.js
Created September 2, 2015 08:37
task gulp babel
var gulp = require('gulp'),
tap = require('gulp-tap'),
gutil = require('gulp-util'),
babel = require("gulp-babel"),
concat = require("gulp-concat"),
plumber = require('gulp-plumber'),
uglify = require('gulp-uglify'),
replace = require('gulp-replace'),
sourcemaps = require('gulp-sourcemaps'),
cached = require('gulp-cached'),
@dhoko
dhoko / demo.html
Created August 31, 2015 14:39
submit
<form-submit></form-submit>
@dhoko
dhoko / buildQueryParam.js
Created August 20, 2015 12:17
Build a query string from an object
/**
* Build query params for an url
* @param {Object} config key=>value
* @return {String}
*/
function getQuery(config) {
var query = Object
.keys(config || {})
.reduce(function (accus, key) {
@dhoko
dhoko / getNetwork.js
Last active August 29, 2015 14:26
Detect network type cf Network API using perf API
/**
* Compute the network type
* @link http://caniuse.com/#feat=resource-timing
*/
function getNetwork() {
var js = performance.getEntriesByName(location.origin + '/js/vendor.min.js')[0] || {duration: 290};
var DELTA = js.duration * 1.2;
// Base calcul for a file 80ko Gzipped
var map = {
@dhoko
dhoko / filter.js
Last active August 29, 2015 14:26
Custom filter for ui.router param (Prevent encoding / etc.)
angular.module('core', ['ui.router'])
.config(function ($stateProvider, $urlMatcherFactoryProvider) {
'use strict';
$urlMatcherFactoryProvider
.type("raw", {
encode: function(val) {return val;},
decode: function(val) {return val;}
});
@dhoko
dhoko / coutLines.es6.js
Last active January 4, 2017 08:00
Count lines added/removed with Bitbucket
(() => {
const CLASS_LIST = [
{type: 'added', className: '.lines-added'},
{type: 'removed', className: '.lines-removed'}
];
const stats = CLASS_LIST
.reduce((accus, o) => {
const total = Array
@dhoko
dhoko / dirToPdf.sh
Created July 14, 2015 16:11
Build a pdf per directory of images
#!/bin/bash
# Base directory containing a list of directories with some picture inside of them
BASE='XXX';
cd $BASE ;
for directory in *
do
echo 'Go to ' $directory;
# Prevent some errors if the name is such as 'Le pull de polo'