Skip to content

Instantly share code, notes, and snippets.

Avatar
🐺

Antoine Pous antoine-pous

🐺
View GitHub Profile
View upsert.typeorm.ts
const upsert = async <Entity>(entity: ObjectType<Entity>, data: Entity, m: EntityManager, rawPKName: string = 'id'): Promise<InsertResult> => {
const keys: string[] = Object.keys(data)
if(keys.length < 1) {
throw Error(`Cannot upsert empty ${entity?.name || entity.constructor.name}`)
}
const updateStr: string = keys.map(key => `"${key}" = EXCLUDED."${key}"`).join(',')
return m.getRepository(entity)
.createQueryBuilder()
@antoine-pous
antoine-pous / Dockerfile
Created Nov 4, 2019
The simplest way to use RabbitMQ delayed message exchange plugin
View Dockerfile
FROM rabbitmq:3.8-management
ADD https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/v3.8.0/rabbitmq_delayed_message_exchange-3.8.0.ez $RABBITMQ_HOME/plugins/rabbitmq_delayed_message_exchange-3.8.0.ez
RUN chown rabbitmq:rabbitmq $RABBITMQ_HOME/plugins/rabbitmq_delayed_message_exchange-3.8.0.ez \
&& rabbitmq-plugins enable --offline rabbitmq_delayed_message_exchange \
&& rabbitmq-plugins enable --offline rabbitmq_consistent_hash_exchange
@antoine-pous
antoine-pous / chuck-norris-facts.txt
Created Sep 17, 2017
Chuck Norris facts i dispense for fun via header X-Chuck-Norris-Fact on my APIs
View chuck-norris-facts.txt
Contrary to popular belief Chuck Norris, not the Florida Supreme Court, made the final judgement on Terri Schiavo's fate. It was a roundhouse kick to the feeding tube.
A mighty crack was heard around the world as Chuck Norris roundhouse kicked the super-continent, Pangaea, beginning continental drift.
Chuck Norris doesn't understand why you should consult your doctor if your erection lasts for more than 4 hours. His erections have been known to last for up to 15 days.
Chuck Norris doesn't look at the toilet paper after he wipes.
Chuck Norris throws midgets for fun. He used to do it competitively, but it all ended horribly when he killed the pope.
Someone once tried to assassinate Chuck Norris's beard but missed hitting Chuck in the face, Chuck proceeded to beat the holy hell out of the guy using nothing but his penis and elbow, Chuck has since installed security on his beard, with a deflector diverting bullets to his face, since he values his beard more than even his rugged good looks.
Chuck Norris can kill a
@antoine-pous
antoine-pous / nvu.sh
Last active Jul 3, 2017
Alias to work with nvm without cache conflict
View nvu.sh
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <gecko@dvp.io> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Antoine POUS
# ----------------------------------------------------------------------------
# Copy this content to your ~/.bashrc then run `source ~/.bashrc`
# Usage: nvu <version> [options]
# Example: nvu 6
View jQuery.fn.serializeJSON.js
$.fn.serializeJSON = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
@antoine-pous
antoine-pous / String.prototype.startWith.js
Created Dec 20, 2016
Detect if string start with needle
View String.prototype.startWith.js
if(!String.prototype.startWith) {
String.prototype.startWith = function(needle) {
return this.substr(0, needle.length) === needle;
}
}
// Usage
'Hello world!'.startWith('hello'); // false
'Hello world!'.startWith('Hello'); // true
@antoine-pous
antoine-pous / storageSwitcher.js
Created Nov 12, 2015
Choose the best storage place available
View storageSwitcher.js
/**
* "THE BEER-WARE LICENSE" (Revision 42):
* <gecko@dvp.io> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return Antoine "Gecko" Pous
*/
// See https://gist.github.com/Antoine-Pous/d0a597ca756b5411ebd2
var cookieChecker = function(){return"undefined"!=typeof navigator.cookieEnabled?(document.cookie="ac=test",e=-1!=document.cookie.indexOf("ac")?!0:!1,document.cookie="ac=; expires=Thu, 01 Jan 1970 00:00:00 UTC",e):navigator.cookieEnabled},
// See https://gist.github.com/Antoine-Pous/c73e5a3a3b1e9507597d
@antoine-pous
antoine-pous / localStorageChecker.js
Created Nov 12, 2015
Check if the localStorage is available
View localStorageChecker.js
/**
* "THE BEER-WARE LICENSE" (Revision 42):
* <gecko@dvp.io> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return Antoine "Gecko" Pous
*/
LSChecker = function() {
try {
localStorage.setItem('test', 'test');
@antoine-pous
antoine-pous / cookieChecker.js
Last active Nov 12, 2015
Check if cookies are available on the browser
View cookieChecker.js
/**
* "THE BEER-WARE LICENSE" (Revision 42):
* <gecko@dvp.io> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Antoine "Gecko" Pous
*/
cookieChecker = function() {
if (typeof navigator.cookieEnabled !== "undefined" ) {
@antoine-pous
antoine-pous / MariaDB_dump.sh
Last active Oct 24, 2015
Archiving all your databases easily
View MariaDB_dump.sh
#!/bin/bash
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <gecko@dvp.io> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Antoine "Gecko" Pous
# ----------------------------------------------------------------------------
USER=<sql_username>
PASSWORD=<sql_password>