Skip to content

Instantly share code, notes, and snippets.

View eloone's full-sized avatar
👀
echo $?

✨Eloone eloone

👀
echo $?
View GitHub Profile
@eloone
eloone / calculate.js
Last active December 17, 2015 11:19
Recursive function to calculate a grid
function calculate(cols, nb){
_this_.cols = cols;
_this_.rows = Math.ceil(nb/cols);
_this_.rest = nb % cols;
_this_.boxDim = _this_.width/cols - 2*_this_.border;
if(_this_.boxDim <= 1){
debug.exec('warn', 'Dimensions of the boxes are too small to be seen');
@eloone
eloone / .bashrc
Last active December 17, 2015 16:29
My git settings
#append this to your .bashrc file in your home
#git auto-completion
source ~/.git-completion.sh
#git prompt
source ~/.git-prompt.sh
GIT_PS1_SHOWCOLORHINTS=true
GIT_PS1_SHOWSTASHSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWUPSTREAM="auto"
@eloone
eloone / key_values.js
Created October 7, 2013 22:19
Print key value pairs in Handlebars
/*
data = {
ctrl_path:
{ message: 'Validator "required" failed for path ctrl_path with value ``',
name: 'ValidatorError',
path: 'ctrl_path',
type: 'required',
value: '' },
@eloone
eloone / filter_object_ppties.js
Last active December 25, 2015 03:19
Filter an object with another object's properties with UnderscoreJs. Allows to filter unwanted properties out of an object by mapping it on a reference object.
/*
var book = {
title : 'brave new world',
author : 'aldous huxley',
rating : '2'
};
var params = {
title : 'lmkwxlkc',
@eloone
eloone / regex.js
Created October 22, 2013 19:21
Some regexes
//matches type like kqsjdlqj@kjdfhdjhf (with @ in the middle)
if(/^[^@]+@[^@]+$/.test(type) === true){
}
@eloone
eloone / binaryInsert.js
Last active June 22, 2019 15:43
Binary Insert
/**
* Example :
* var a = [2,7,9];
* binaryInsert(8, a);
*
* It will output a = [2,7,8,9]
*
*/
function binaryInsert(value, array, startVal, endVal){
var range = document.createRange();//Create a range (a range is a like the selection but invisible)
range.selectNodeContents(this.target);//Select the entire contents of the element with the range
range.setEnd(this.target.firstChild, pos);
range.collapse();//collapse the range to the end point. false means collapse to end rather than the start
selection = window.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
selection.addRange(range);
@eloone
eloone / upload_file.js
Created July 25, 2015 21:14
upload file in angularjs
(function(angular){
angular.module('folio.components.project.thumbUpload', [])
.factory('ThumbUpload', ['$q', '$http', '$log', ThumbUploadProvider]);
function ThumbUploadProvider($q, $http, $log){
function ThumbUploadService(){
this.upload = function(file, filename){
var deferred = $q.defer();
var fd = new FormData();
(function(angular){
angular.module('app.lib.http.interceptorRequestFormatter', ['nvision.lib.xmlRequestFormatter'])
.config(['$httpProvider',function($httpProvider) {
$httpProvider.interceptors.push('InterceptorRequestFormatter');
}])
.factory('InterceptorRequestFormatter', ['XmlRequestFormatter', InterceptorRequestFormatterProvider]);
function InterceptorRequestFormatterProvider(XmlRequestFormatter){
// Formats the request data
/*
Usage:
$onceRendered(function(){ // do your thing});
*/
(function(angular){
'use strict';
angular.module('app.lib.onceRendered', [])
.factory('$onceRendered', ['$U', '$http', '$timeout', ServiceFactory]);
function ServiceFactory($U, $http, $timeout){