Skip to content

Instantly share code, notes, and snippets.

@johnchristopher
johnchristopher / on-duplicate-key-update.sql
Last active August 29, 2015 14:22
Update field if it exists or insert it if it doesn't (with MySQL ON DUPLICATE KEY UPDATE)
mysql > CREATE TABLE `mytable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`myvalue` int(11) NOT NULL,
`myothervalue` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `myvalue_unique` (`myvalue`), -- C'est le champ qui s'il existe alors on le met à jour,
KEY `myvalue_idx` (`myvalue`) -- sinon on crée un nouvel enregistrement
)
Query OK, 0 rows affected (0.09 sec)
{"nbformat_minor": 0, "cells": [{"execution_count": 2, "cell_type": "code", "source": "%matplotlib inline\nfrom pylab import *\nx=linspace(0, 2*pi)\ny=sin(x)\nplot(x, y)", "outputs": [{"execution_count": 2, "output_type": "execute_result", "data": {"text/plain": "[<matplotlib.lines.Line2D at 0x60abad0>]"}, "metadata": {}}, {"output_type": "display_data", "data": {"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEACAYAAAC9Gb03AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHwJJREFUeJzt3Xe4XWWZ/vHvDQGRLqiAwFBDCD3gL6KIRMqQgAYYpYQq\nNYAxFBs4/DSA46CgtAwgECAQDFKVDkESQFFM6JIEQslMqKJSBKQEnvljLcZDOGXvs8u71tr357q4\ncvY5e+91k5w858m73qKIwMzMqmuh1AHMzKy1XOjNzCrOhd7MrOJc6M3MKs6F3sys4lzozcwqruFC\nL+kCSS9IeriX55whaY6kByUNafSaZmZWu2Z09BcCw3v6oqQdgLUjYiBwCHB2E65pZmY1arjQR8Rd\nwEu9PGUkMDF/7j3AspJWaPS6ZmZWm3aM0a8MzOvy+GlglTZc18zMaN/NWC3w2PsumJm1yYA2XOMZ\nYNUuj1fJP/cBklz8zcz6ISIWbKY/oB2F/lpgDHCZpM2BlyPihe6e2FfYIpM0LiLG9f/1DAZOAD4P\nnAXcCcyI4PUaX78csAfwNbIfppOAiyKY2fdrG8uemvOn5fxp1dIkN2N65WTgbmCQpHmSDpA0WtJo\ngIi4EXhS0uPAz4HDG71m
{"nbformat_minor": 0, "cells": [{"execution_count": 2, "cell_type": "code", "source": "s='12'", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 3, "cell_type": "code", "source": "map(int, s)", "outputs": [{"execution_count": 3, "output_type": "execute_result", "data": {"text/plain": "[1, 2]"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "Note que `int` est invoqu\u00e9 sans les parenth\u00e8ses.", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "[int(x) for x in s]", "outputs": [{"execution_count": 4, "output_type": "execute_result", "data": {"text/plain": "[1, 2]"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "List comprehension. C'est d\u00e9j\u00e0 plus _pythonic_ comme ils disent.", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "filter(lambda l: l == '1', s)", "outputs": [{"execution_count": 14, "o
@johnchristopher
johnchristopher / pandoc.sh
Last active August 29, 2015 14:04
Pandoc
pandoc input.md -s -S --toc -c github-pandoc.css -t html5 -o output.html
@johnchristopher
johnchristopher / gist:b011fc648c3637420444
Last active August 29, 2015 14:03 — forked from stran12/gist:1394757
How to install cGit on Nginx (Ubuntu server)

How to install cGit on Nginx (Ubuntu server)

Step-by-step installtion of cGit on nginx without funky rewrite rules.

Pre-requisites

This is for

@johnchristopher
johnchristopher / extract-audio-from-video.sh
Last active January 17, 2023 04:15
FFmpeg subtitles commands
ffmpeg -i input.mp4 \
-map 0:1 \
-c:a copy \
-y output.m4a
@johnchristopher
johnchristopher / 0_reuse_code.js
Created June 18, 2014 23:36
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#! /bin/sh
#
sed 's/t p/t-p/gi' $1 |
sed 's/c s/c-s/gi' |
sed 's/c e/c-e/gi' |
sed 's/d p/d-p/gi' |
sed 's/N s/N-s/gi' |
sed 's/l I/l-I/gi' |
sed 's/P A/P-A/gi' |
#!/bin/bash
# Last modified: 2011 Dec 14
# Version 0.9
# Author: Florian CROUZAT <contact@floriancrouzat.net>
# Feel free to do whatever you want with this file.
# Just make sure to credit what deserve credits.
# Arg(s): $1 - Arte+7 html URL of the page used to actually see the video.