Skip to content

Instantly share code, notes, and snippets.

View JulienBreux's full-sized avatar

Julien Breux JulienBreux

View GitHub Profile
@atomrc
atomrc / localStorageFallback.js
Created October 28, 2015 15:50
Stupid fallback for localStorage when browser doesn't support it
/**
* Warning : only use this piece of code
* if storing things in the localStorage is
* NOT vital for your application to work
**/
/* function noop
* simply does nothing
**/
function noop() {}
@blixt
blixt / Event.swift
Last active January 19, 2023 19:42
A simple Event class for handling events in Swift without strong retain cycles.
import Foundation
private class Invoker<EventData> {
weak var listener: AnyObject?
let closure: (EventData) -> Bool
init<Listener : AnyObject>(listener: Listener, method: (Listener) -> (EventData) -> Void) {
self.listener = listener
self.closure = {
[weak listener] (data: EventData) in
@mdwhatcott
mdwhatcott / custom_json.go
Created July 29, 2015 17:15
Example of implementing MarshalJSON and UnmarshalJSON to serialize and deserialize custom types to JSON in Go. Playground: http://play.golang.org/p/7nk5ZEbVLw
package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
)
func main() {
@MoOx
MoOx / index.js
Last active February 9, 2024 22:44
Export/import github labels
// go on you labels pages
// eg https://github.com/cssnext/cssnext/labels
// paste this script in your console
// copy the output and now you can import it using https://github.com/popomore/github-labels !
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
@tjamps
tjamps / README.md
Last active February 29, 2024 14:57
Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authentication
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 2 framework. The following SF2 bundles are used :

@simlegate
simlegate / custom-error-page
Created October 31, 2014 05:35
Nginx return custom json
error_page 400 404 405 =200 @40*_json;
location @40*_json {
default_type application/json;
return 200 '{"code":"1", "message": "Not Found"}';
}
error_page 500 502 503 504 =200 @50*_json;
location @50*_json {
@whyrusleeping
whyrusleeping / gob.go
Created October 16, 2014 06:07
golang gob interface example
package main
import (
"bytes"
"encoding/gob"
"fmt"
)
type MyFace interface {
A()
@weapp
weapp / nginx.conf
Created August 4, 2014 17:21
Return common errors as json in Nginx
error_page 500 /500.html;
location /500.html{
return 500 '{"error": {"status_code": 500,"status": "Internal Server Error"}}';
}
error_page 502 /502.html;
location /502.html{
return 502 '{"error": {"status_code": 502,"status": "Bad Gateway"}}';
}
@bryfry
bryfry / gzip.go
Last active August 28, 2023 09:23
Idiomatic golang net/http gzip transparent compression (works with Alice)
package main
import (
"compress/gzip"
"io"
"net/http"
"strings"
)
// Gzip Compression
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)