Skip to content

Instantly share code, notes, and snippets.

@dhoko
dhoko / zipthemall.sh
Created February 17, 2014 10:34
Compress each files inside a directory
for directory in $(ls)
do
echo Move to $directory;
cd $directory && zip $directory * && cd .. && mv $directory/$directory.zip . || echo Erro meine cheneral;
done;
@dhoko
dhoko / ObjectPathValue.js
Last active August 29, 2015 13:56
Get value from an object from a path inside the object
/**
* Get a value from an object by its path
* @param {Object} obj
* @param {String} path Path to the value key1.key2.key3...
* @return {Object} Value
*/
function valuePathObject(obj, path) {
path.split(".").forEach(function(item){
obj = obj[item]
});
@dhoko
dhoko / hex2rgb.php
Last active August 29, 2015 14:01
Color: Hex to rgb
<?php
// Without #
list($r,$g,$b) = sscanf($color, "%02x%02x%02x");
// With #
list($r,$g,$b) = sscanf($color, "#%02x%02x%02x");
// from http://stackoverflow.com/questions/15202079/convert-hex-color
// Concatenate your partials and append them to index.html
gulp.task('templates', function() {
var stream = streamqueue({objectMode: true});
stream.queue(gulp.src([
'./src/layout/header.html',
'./src/layout/body.html'
]));
stream.queue(gulp.src('./src/partials/**/*.html').pipe(partials()));
@dhoko
dhoko / template.js
Last active August 29, 2015 14:01
Template
// Fichier dans le dossier task pour le cas deux
var gulp = require('gulp'),
concat = require("gulp-concat")
es = require('event-stream')
partials = require('gulp-partial-to-script')
streamqueue = require('streamqueue');
module.exports = function() {
"use strict";
// ça casse que si je relance gulp.
ìf(cartList.models.length) {
generator(cartList.models,0,cartList.models.length);
}
@dhoko
dhoko / gist:0a2dfac059e72a2f39cd
Created May 21, 2014 09:27
i18n with Angular
/**
* i18nLoad directive
* Load a translation from a click on a button with the attr i18n-load
*/
module.exports = ['localize', function(localize) {
return {
restrict: "A",
link: function(scope,el,attr) {
el.on('click',function() {
var gulp = require('gulp'),
gutil = require('gulp-util'),
watchify = require("watchify"),
concat = require("gulp-concat"),
streamqueue = require('streamqueue'),
streamify = require('gulp-streamify'),
source = require('vinyl-source-stream'),
livereload = require('gulp-livereload');
/**
@dhoko
dhoko / padNumber.js
Created August 5, 2014 08:24
Add padding to a number
function padNumber(n, pad) {
var str = '' + n;
return '000000000'.slice(str.length,pad) + str;
}
@dhoko
dhoko / script.js
Last active August 29, 2015 14:05
Github emoticons display
function doRequest(url, cb) {
// create the request here
cb = cb || function(){};
var xhr = new XMLHttpRequest();
var requestUrl = url;
xhr.open("GET", requestUrl, true);
xhr.onreadystatechange = function() {
var status;