Skip to content

Instantly share code, notes, and snippets.

View teebot's full-sized avatar

Thibaut Nguyen teebot

View GitHub Profile
@teebot
teebot / wrapper.js
Created January 27, 2016 11:25
Wrap multiple functions in one
const fnWrapper = (...args) => () => args.forEach(f => f());
const method1 = document.write.bind(document, ['hello']);
const method2 = document.write.bind(document, ['world']);
const wrapped = fnWrapper(method1, method2);
wrapped();
@teebot
teebot / sticky-scroll.coffee
Created January 12, 2016 11:17
sticky scroll directive in coffeescript
appDirectives.directive 'stickyScroll', ->
return {
restrict: 'A'
link: (scope, element, attr) ->
unregisterWatch = scope.$watch(
-> return element[0].scrollHeight,
->
element[0].scrollTop = element[0].scrollHeight
)
#map
@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
@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 / 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: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 / 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 / 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 / fixed-counter-on-scrolling.markdown
Created November 27, 2014 14:39
fixed counter on scrolling