Skip to content

Instantly share code, notes, and snippets.

View antoine-pous's full-sized avatar
🐺

Antoine Pous antoine-pous

🐺
View GitHub Profile
@antoine-pous
antoine-pous / upsert.typeorm.ts
Last active November 11, 2023 21:17
TypeORM upsert
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 November 4, 2019 17:31
The simplest way to use RabbitMQ delayed message exchange plugin
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 September 17, 2017 12:48
Chuck Norris facts i dispense for fun via header X-Chuck-Norris-Fact on my APIs
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 November 11, 2023 21:18
Alias to work with nvm without cache conflict
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <[email protected]> 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
$.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 December 20, 2016 12:09
Detect if string start with needle
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 November 12, 2015 14:21
Choose the best storage place available
/**
* "THE BEER-WARE LICENSE" (Revision 42):
* <[email protected]> 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 November 12, 2015 12:12
Check if the localStorage is available
/**
* "THE BEER-WARE LICENSE" (Revision 42):
* <[email protected]> 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 November 11, 2023 21:19
Check if cookies are available on the browser
/**
* "THE BEER-WARE LICENSE" (Revision 42):
* <[email protected]> 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 November 11, 2023 21:19
Archiving all your databases easily
#!/bin/bash
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <[email protected]> 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>