Skip to content

Instantly share code, notes, and snippets.

View Tronix117's full-sized avatar

Jeremy TRUFIER Tronix117

View GitHub Profile

TP - WIK-JS-302 - Introduction au Typescript (orienté WebService)

Objectifs

Sujet

Concevoir un ORM qui permet de communiquer avec le service externe https://jsonplaceholder.typicode.com

Cet ORM sera réalisé en TypeScript et typé au maximum.

const app = require('express')()
const db = {
users: [
{ id: 0, firstname: 'Jean', lastname: 'Bond' },
{ id: 1, firstname: 'Emilie', lastname: 'Lol' },
]
}
class HttpError extends Error {
@Tronix117
Tronix117 / backbone-sync-with-pagination.coffee
Last active August 29, 2015 14:01
Backbone pagination using Content-Range header
# Backbone Pagination with header
#
# Get remote number of resources, and add it in the `remoteCount` attribute of the collection
# this attribute can then be use to create proper pagination.
#
# Expected format is an header `Content-Range` with following format:
# `resource 40-49/234` (HTTP 1.1 format)
# * `resource` is the name of the resource (can be `resource`, not important)
# * `40-49` is the range of returned items (item 40 to item 49)
# * `234` is the total number of items (this is the important part)
@Tronix117
Tronix117 / saferize-click.coffee
Last active August 29, 2015 13:56
Prevent 'click' callback to be called when 'dblClick' callback should be called
# Saferize Click
#
# saferClick = saferizeClick singleClickCallback, doubleClickCallback
#
# Prevent 'click' callback to be called when 'dblClick' callback should be called
#
# Exemple:
#
# Better to add it to underscore with following:
#
@Tronix117
Tronix117 / smart-navigate.coffee
Last active December 31, 2015 01:59
Chaplin Smart Navigation. smartNavigate will automatically select and trigger the best route using only given route parameters
# Chaplin Smart Navigation
#
# Chaplin.mediator.smartNavigate params, options
#
# Add a smartNavigate method to Chaplin.mediator, it will automaticaly select
# the best route using only route params in first argument.
#
# Keep automaticaly current route params, except if they are explicitely set to
# null or if `reset: true` is passed as second argument.
#
@Tronix117
Tronix117 / bouyguemms
Created July 9, 2013 17:04
Download MMS from Bouygues Telecom (useful for Numericable iPhone owner's). Usage: bouyguemms code [yourPhoneNumber [whereToDownload]]. Ex: bouyguemms i9u7sw
#!/bin/sh
PHONE=${2-yourdefaultphonenumber}
CODE=$1
OUTPUT=${3-.}
BASEURL=http://www.lire-mms.bouyguestelecom.fr/mmbox
SESSIONID=`curl -s -X POST -d "msisdn=$PHONE&msgid=$CODE" -D- "$BASEURL/otp.html" -o /dev/null | grep JSESSIONID | cut -d'=' -f2 | cut -f1 -d' ' | tr "\!" "\\\!"`
@Tronix117
Tronix117 / gist:5553599
Created May 10, 2013 10:20
Relational layer over modal for Backbone. Can manage single id or multiple id relations between models. one-to-one, one-to-many, many-to-many, smart selection of id key, or possible to specify it ('through' keyword). Autofetch can also fetch missing related collection models.
###
# Adding relation support to models
Note: Given collections were here Singletons in this project, you can also use instances of collections instead.
relations:
friends: require 'collections/Users' # @get('friends') will return an array of friend if friends_ids or friends_id is an array
store: require 'collections/Store' # @get('store') will return the store object if there is a store_id
subcategories:
through: 'category_ids'
@Tronix117
Tronix117 / Cakefile
Last active December 16, 2015 13:38
Cakefile script to easily build Jade, Stylus and CoffeeScript source files for little projects or static website. Also provide consistent website structure. Also watch Jade and Stylus dependencies (if you modify an import or an extends, every file which use it will be rebuilt). Include a basic support of I18n - Internationalization with support …
###
# Cakefile
#
# Build easily Stylus, CoffeeScript and Jade source files
# for little projects.
#
# First install requirements using `npm install`
#
# Then, modify the config in the `config.coffee` file
#
@Tronix117
Tronix117 / I18n.coffee
Created November 19, 2012 02:11
I18n - JavaScript and CoffeeScript
###
# I18n class
# Allow you to add Internationalization to your CoffeeScript application
#
# Just call it with a `require 'util/I18n'` or `new I18n` if you don't have a `require` system
# More informations here: https://github.com/Tronix117/tradify
# Translation files should be saved in `locales/{langage code}.coffee`
#
# Then you can translate everything with `tr('{0} day', numberOfDay)`
#
@Tronix117
Tronix117 / crypt_id.rb
Created August 12, 2012 19:22
Algorithm: Rails crypt integer to random short string, can be used as link shortener (by directly crypting databse ids). 1296 possibility for each Int (for each crypting key). String generated are not linear and also include a validity check (hashsum), an
##
# MonkeyPatch crypt_id
#
# Provide an efficient way to crypt an id, with
# different possibility for each id.
#
# Three provided methods are:
# Int.crypt_id(key='')
# String.decrypt_id(key='')
# String.change_charset(charset_from, charset_to)