Skip to content

Instantly share code, notes, and snippets.

View cedricvidal's full-sized avatar

Cedric Vidal cedricvidal

View GitHub Profile
@cedricvidal
cedricvidal / README.md
Created November 15, 2018 09:57
Optimized Oracle pagination

Where :

  • FIRST_ROWS(N) tells the optimizer, "Hey, I'm interested in getting the first rows, and I'll get N of them as fast as possible."
  • :MAX_ROW_TO_FETCH is set to the last row of the result set to fetch—if you wanted rows 50 to 60 of the result set, you would set this to 60.
  • :MIN_ROW_TO_FETCH is set to the first row of the result set to fetch, so to get rows 50 to 60, you would set this to 50.

Source https://blogs.oracle.com/oraclemagazine/on-rownum-and-limiting-results

@cedricvidal
cedricvidal / s.py
Created October 22, 2018 17:34
Python 2 non blocking asyncore port forwarding TCP proxy
#!/usr/bin/env python
#
# s.py - a simple port forwarder using asyncore
#
# by Yusuke Shinyama, *public domain*
# http://www.unixuser.org/~euske/python/s.py
#
import sys, socket, asyncore
@cedricvidal
cedricvidal / install_docker.sh
Created October 28, 2017 10:59
Howto install docker on OSX latest known working way
brew cask install docker
@cedricvidal
cedricvidal / setup_python_env.sh
Last active October 28, 2017 16:46
Python direnv setup
#!/usr/bin/env bash
REQS_MD5=$(md5 -q requirements.txt $(cat requirements.txt | grep "^-r " | cut -d " " -f 2))
if [ ! -f .direnv/reqs_md5 ] || [ "$(cat .direnv/reqs_md5)" != "${REQS_MD5}" ]; then
echo "Installing python requirements"
pip3 install -r requirements.txt
mkdir -p .direnv
echo ${REQS_MD5} > .direnv/reqs_md5
else
echo "Python requirements up to date"
fi
@cedricvidal
cedricvidal / randomwords.sh
Last active October 6, 2017 19:04
Generates random words in an infinite 1Hz loop
WORDFILE="/usr/share/dict/words"
NUMWORDS=1
#Number of lines in $WORDFILE
tL=`awk 'NF!=0 {++c} END {print c}' $WORDFILE`
while :
do
rnum=$((RANDOM%$tL+1))
sed -n "$rnum p" $WORDFILE
@cedricvidal
cedricvidal / get_completions.sh
Created July 9, 2017 13:11
Accessing tab-completion programmatically in Bash
#
# Author: Brian Beffa <brbsix@gmail.com>
# Original source: https://brbsix.github.io/2015/11/29/accessing-tab-completion-programmatically-in-bash/
# License: LGPLv3 (http://www.gnu.org/licenses/lgpl-3.0.txt)
#
get_completions(){
local completion COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMPREPLY=()
# load bash-completion if necessary
@cedricvidal
cedricvidal / gen-self-signed-certs.sh
Created June 5, 2017 17:30
Generates a self signed certificate
#!/bin/sh
DOMAIN=${1:-localhost}
openssl genrsa -out $DOMAIN.key 2048
openssl req -new -x509 -key $DOMAIN.key -out $DOMAIN.cert -days 3650 -subj /CN=$DOMAIN
@cedricvidal
cedricvidal / nginx.conf
Last active June 5, 2017 16:57 — forked from foxxyz/nginx.conf
Serve current directory via nginx
# Extremely basic development setup to serve the current directory at http://localhost:9001
# Start nginx in this directory with `nginx -p . -c $PWD/nginx.conf`
# Stop nginx with `nginx -p . -s stop`
events {}
daemon off;
http {
# Serve files with correct mimetypes on OSX
# location may have to be adjusted depending on your OS and nginx install
cat image.jpg | base64 | vault write /secret/image.jpg value=-
vault read -format=raw -field=value /secret/image.jpg | base64 --decode > image.out.jpg
@cedricvidal
cedricvidal / .envrc
Created January 17, 2017 17:08
Load OpenStack OS_* env variables automatically using direnv and envchain
layout python
PATH_add bin
ENVCHAIN_NS=qs-ovh-cloud
if [ -z "$OS_PASSWORD" ]; then
if type envchain > /dev/null; then
echo "Loading OS_PASSWORD env var from keychain"
direnv_load envchain $ENVCHAIN_NS direnv dump
else
echo