Skip to content

Instantly share code, notes, and snippets.

View teebot's full-sized avatar

Thibaut Nguyen teebot

View GitHub Profile
@teebot
teebot / gist:e20ad1a824a25ebc4738
Created June 5, 2014 09:05
any object by its id from a collection
employees = [{ id : 1, name : "tib" }, { id : 2, name : "dude" }]
search = (input, id) ->
for i in [0..input.length - 1]
if (input[i].id == id)
return input[i];
return null
@teebot
teebot / gist:06c1361f481a7d66fb2f
Created June 6, 2014 22:48
Un-commit last un-pushed git commit without losing the changes
git reset HEAD~1 --soft
@teebot
teebot / fixed-counter-on-scrolling.markdown
Created November 27, 2014 14:39
fixed counter on scrolling
@teebot
teebot / user-prefs-service.coffee
Last active August 29, 2015 14:14
Angular LocalStorage Key Value Store
angular.factory 'userPrefsService', (localStorageService) ->
STORAGE_KEY = 'userPrefs'
userPrefs = localStorageService.get(STORAGE_KEY) || {}
return {
set: (key, obj) ->
if !key? || key.length == 0
throw new Error('A key is required to store a value in the store')
if obj == null
delete userPrefs[key]
@teebot
teebot / notification-service.coffee
Created January 30, 2015 12:11
A desktop notification angular service that handles browser permissions
# This service is a wrapper for the Notification API
# It ensures only one notification is shown at a time
angular.module('acmeServices').factory 'notificationService', ($window, $timeout, userPrefsService) ->
ALREADY_PROMPTED_UP_KEY = 'notifAlreadyPrompted'
LAST_NOTIF_TIME_UP_KEY = 'lastNotifTime'
NOTIF_GRANTED_STATE = 'granted'
NOTIF_DENIED_STATE = 'denied'
NOTIF_TIMEOUT_MS = 20000
@teebot
teebot / gist:d063f80ba1913a4a40cd
Created February 6, 2015 09:26
Regex replace a JSON dictionary by an array of objects
{"BE":"Belgium"}, {"IT":"Italia"}
to
[{ "code": "BE", "name": "Belgium"}, { "code": "IT", "name": "Italia"}]
replace this ([^{},:]*):([^{},:]*)
with this : { "code":$1, "name": $2 }
@teebot
teebot / gist:3918797e1c8133306914
Created March 25, 2015 11:44
Custom Event JS
var event = new CustomEvent('newMsg', { detail: 'Hello people' });
window.addEventListener('newMsg', function handler(e){ console.log(e.detail) }, false);
window.dispatchEvent(event);
@teebot
teebot / gist:183538cd7063a9a524e3
Created April 16, 2015 07:20
Preferences.sublime-settings
{
"caret_extra_width": 2,
"color_scheme": "Packages/Theme - Afterglow/Afterglow.tmTheme",
"font_size": 14,
"ignored_packages":
[
"Vintage"
],
"tabs_medium": true,
"theme": "Afterglow.sublime-theme",
@teebot
teebot / bootNodeReact.sh
Last active August 29, 2015 14:20
bash node projects
#!/bin/bash
read -e -p "Project path: " pathName
mkdir -p $pathName && cd $pathName
npm init -f
npm install --save babel babelify body-parser browserify cookie-parser express grunt grunt-browserify grunt-cli jade minifyify react reflux
dirArray=(data public react views)
for dir in ${dirArray[*]}
do
mkdir $dir
#map