Skip to content

Instantly share code, notes, and snippets.

Vincent Durmont vdurmont

View GitHub Profile
@vdurmont
vdurmont / jsonp-callback.html
Last active Aug 29, 2015
How to use JSONP with userinfo.io API
View jsonp-callback.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>UserInfo.io — JSONP callback</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
function userinfoCallback(data) {
console.log("I can now do awesome things with this beautiful data I just received!");
View hello-amd.js
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else {
root.Hello = factory();
}
}(this, function() {
return function() {
var done = false;
return {
@vdurmont
vdurmont / Main.java
Created Jan 7, 2014
First use of APIPixie
View Main.java
// Create an APIPixie instance
APIPixie pixie = new APIPixie("http://api.mydistantservice.com");
// Retrieve an APIService for your object
APIService<Message> msgService = pixie.getService(Message.class);
// Start communicating with the distant API
Message msg = msgService.get(42L);
// Now do stuff with the object!
View gist.rb
require 'cgi'
require 'open-uri'
# Require the ActiveSupport::Cache module
require 'active_support/cache'
module Fiftyfive
module Liquid
class GistTag < ::Liquid::Tag
def initialize(tag_name, gist_ref, tokens)
@vdurmont
vdurmont / bug.json
Created Nov 26, 2013
model example
View bug.json
{
"id": 42,
"title": "Wrong format for the creation date",
"creation": "2013-11-27T04:33:35Z",
"status": "OPEN",
"assignee": "Vincent"
}
@vdurmont
vdurmont / config.json
Created Nov 26, 2013
database config for a mongodb-based app
View config.json
{
"host": "localhost",
"dbname": "example"
}
@vdurmont
vdurmont / routes.js
Created Nov 26, 2013
database and request handler for a basic express.js API
View routes.js
var config = require('./config.json');
var monk = require('monk');
var db = monk(config.host+'/'+config.dbname);
var collection = db.get('bugs');
// Returns all the bugs
exports.getAll = function(req, res) {
collection.find({}, function(err, bugs){
if (err) res.json(500, err);
else res.json(bugs);
@vdurmont
vdurmont / app.js
Created Nov 26, 2013
main file for a basic express.js API
View app.js
var express = require('express');
var routes = require('./routes.js');
var app = express();
app.use(express.bodyParser());
app.get('/', routes.getAll);
app.post('/', routes.create);
app.get('/:id', routes.get);
app.put('/:id', routes.update);
@vdurmont
vdurmont / package.json
Created Nov 26, 2013
Basic package.json to import express.js and monk in a node project
View package.json
{
"name": "MyApp",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.4.4",
"monk": "0.7.1"
}
}
View user.jade
extends layout
block content
p Happy to see you again, #{name} !
p I'm happy to show your reversed name: <strong>#{reversedName}</strong>!
You can’t perform that action at this time.