Skip to content

Instantly share code, notes, and snippets.

@compnski
compnski / table_hash.go
Last active April 14, 2023 03:20
Builds a SQL statement to hash a table in any of postgres/mysql/redshift, with the same result across the 3.
package main
import (
"flag"
"fmt"
"strings"
)
const DB_REDSHIFT = "redshift"
const DB_POSTGRES = "postgres"
@Kartones
Kartones / postgres-cheatsheet.md
Last active May 8, 2025 09:19
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@fperez
fperez / ipshell_doctest.py
Created February 1, 2014 03:39
IPython Shell that can be embedded when called in a doctest run
"""Implement a version of `IPython.embed()` which works during doctesting.
This provides a `dt_embed()` function that is similar to `IPython.embed`, but
which can run when used inside code that will be run via doctests (where the
default `embed` locks up due to the hijacking of `sys.stdout` that doctest
performs.
See https://github.com/ipython/ipython/issues/90 for the full details.
"""
@edsu
edsu / wikichanges.js
Created January 21, 2014 14:53
paste this in your browser's console window and smoke it :-)
var w = new EventSource("https://wikipedia-edits.herokuapp.com/sse");
w.onmessage = function(event) {
change = JSON.parse(event.data);
console.log(change);
}
@dergachev
dergachev / squid-deb-proxy_on_docker.md
Last active February 21, 2025 02:49
Caching debian package installation with docker

TLDR: I now add the following snippet to all my Dockerfiles:

# If host is running squid-deb-proxy on port 8000, populate /etc/apt/apt.conf.d/30proxy
# By default, squid-deb-proxy 403s unknown sources, so apt shouldn't proxy ppa.launchpad.net
RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt
RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | grep squid-deb-proxy \
  && (echo "Acquire::http::Proxy \"http://$(cat /tmp/host_ip.txt):8000\";" > /etc/apt/apt.conf.d/30proxy) \
  && (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) \
  || echo "No squid-deb-proxy detected on docker host"
@perrygeo
perrygeo / TODO
Last active December 31, 2022 21:24
Ansible playbook for a full dev environment
TODO
implement security measures
git config
config files
full sublimetext config
set up openvpn
rdesktop and network drive to terra
set up evolution
RStudio
@ib-lundgren
ib-lundgren / github_flask_oauth2.py
Created September 10, 2013 10:53
Example of how to use Flask with requests-oauthlib to fetch a GitHub user profile using an OAuth 2 token.
from requests_oauthlib import OAuth2Session
from flask import Flask, request, redirect, session, url_for
from flask.json import jsonify
import os
app = Flask(__name__)
# This information is obtained upon registration of a new GitHub
client_id = "<your client key>"
@fperez
fperez / 00-Setup-IPython-PySpark.ipynb
Last active December 21, 2015 23:48
HowTo for starting an IPython Notebook server
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Build your own private, encrypted, open-source Dropbox-esque sync folder

Prerequisites:

  • One or more clients running a UNIX-like OS. Examples are given for Ubuntu 12.04 LTS, although all software components are available for other platforms as well (e.g. OS X). YMMV
  • A cheap Ubuntu 12.04 VPS with storage. I recommend Backupsy, they offer 250GB storage for $5/month. Ask Google for coupon codes.

Software components used:

  • Unison for file synchronization
  • EncFS for folder encryption
@rwjblue
rwjblue / rsa_decrypt.rb
Last active March 16, 2016 16:18
Public-key encryption with Ruby.
require 'openssl'
require 'base64'
ciphertext = Base64.decode64("CIPHERTEXT GOES HERE")
passphrase = ENV['PRIVATE_KEY_PASSPHRASE'] # read in from environment
private_key = OpenSSL::PKey::RSA.new(File.read('path/to/private_key.pem'), passphrase)
plaintext = private_key.private_decrypt(ciphertext, OpenSSL::PKey::RSA::PKCS1_PADDING)
puts "Plain text is: " + plaintext