Skip to content

Instantly share code, notes, and snippets.

View amessinger's full-sized avatar
🐠

Antonin Messinger amessinger

🐠
  • Ponton 17
  • Paris, France
View GitHub Profile
@amessinger
amessinger / element-events-and-binded-functions
Created February 28, 2013 13:48
Given an element, return all events and binded functions
$('#my-element').each( function() {
$.each($(this).data("events"), function(i, event) {
console.log(i);
$.each(event, function(j, h) {
console.log(h.handler);
});
});
});
@amessinger
amessinger / cors.js
Created March 1, 2013 15:46
A policy to allow CORS responses on your sailsjs-based (or express) API.
module.exports = function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
}
@amessinger
amessinger / semaphore.js
Last active December 14, 2015 16:29
Gives you the ability to create or override methods returning deferred objects so that only one request can be fired at a time.
// examples:
// create a new function : customRequest = Semaphore.request($.ajax);
// override a function: Backbone.sync = Semaphore.request(Backbone.sync);
Semaphore = function() {
// private attributes
var available = true;
// private api
function lock() {
available = false;
@amessinger
amessinger / jquery.ajax.cors-ie.js
Last active December 15, 2015 12:49
Override jquery ajax if IE
$(function() {
if ('XDomainRequest' in window && window.XDomainRequest !== null) {
jQuery.ajaxSettings.xhr = function() {
try { return new XDomainRequest(); }
catch(e) { }
};
jQuery.support.cors = true;
}
})
# The best distro for LXC right now is ubuntu since you'll have almost no config to get LXC networking working
# All LXC commands have to be run as root (or sudo)
# 1. DO IT once on the host
# 1.1 install lxc
apt-get install lxc
# 1.2 enable nat on iptables
echo 1 > /proc/sys/net/ipv4/ip_forward
@amessinger
amessinger / proxy-cors.conf
Created February 28, 2017 16:37
Proxy Cors Config for Nginx
upstream service {
server {{ ip }}:{{ port }};
}
server {
if ($http_origin ~* (https?://localhost(:[0-9]+)?)) {
rewrite ^ /__cors__/$request_method$uri last;
}
@amessinger
amessinger / proxy-http2.conf
Created March 1, 2017 13:59
Proxy HTTP2 Config for Nginx
upstream service {
server 127.0.0.1:4200;
}
server {
listen 443 ssl http2 default_server;
server_name localhost;
# cd /etc/nginx/ssl
# openssl req -x509 -sha256 -newkey rsa:2048 -keyout cert.key -out cert.pem -days 1024 -nodes -subj '/CN=local'
@amessinger
amessinger / Dockerfile-fakes3
Last active March 23, 2017 09:11
Fake S3 Docker Container
# https://github.com/jubos/fake-s3
FROM alpine
EXPOSE 80
RUN apk update
RUN apk add ruby ruby-rdoc ruby-irb ruby-io-console
RUN gem install fakes3
RUN mkdir -p /var/fakes3
@amessinger
amessinger / index.js
Created March 27, 2017 13:28
expressjs + sequelizejs filterable route
app.get('/albums', function (req, res) {
Album
.findAll({
where: getQueryFilters(req.query),
order: ['albumartist']
})
.then((items)=> {
res.json(items);
});
});
@amessinger
amessinger / debounce.js
Created November 22, 2017 15:50
Debounce wrapper
function debounce(func, wait) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(()=> {
func.apply(this, args);
}, wait);
};
}