Skip to content

Instantly share code, notes, and snippets.

@emilong
emilong / postgres_queries_and_commands.sql
Last active June 15, 2018 16:46 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- index usage stats
SELECT
relname,
100 * idx_scan / (seq_scan + idx_scan) percent_of_times_index_used,
n_live_tup rows_in_table
FROM
pg_stat_user_tables
WHERE
seq_scan + idx_scan > 0
ORDER BY
@matthewrudy
matthewrudy / db-structure-clean.rake
Created February 26, 2017 23:40
Clean differences from your rake db:structure:dump - it seems to work for 9.4, 9.5 and 9.6
# frozen_string_literal: true
namespace :db do
namespace :structure do
STRUCTURE_PATH = 'db/structure.sql'
def clean_structure_file
original = File.read(STRUCTURE_PATH)
cleaned = original.dup
#!/usr/bin/env ruby
#
# Convert VCR cassettes that use basic auth to work with Webmock 2. Takes the folder where the VCR
#cassettes are stored as an argument.
require 'yaml'
require 'base64'
FOLDER = File.expand_path(ARGV[0])
FILES = Dir["#{File.join(FOLDER, '**', '*.yml')}"]
@harto
harto / before.js
Created April 20, 2016 17:33
Mocha before() & beforeEach() execution order with nested describe()
'use strict';
describe('mocha before hooks', function () {
before(() => console.log('*** top-level before()'));
beforeEach(() => console.log('*** top-level beforeEach()'));
describe('nesting', function () {
before(() => console.log('*** nested before()'));
beforeEach(() => console.log('*** nested beforeEach()'));
it('is a nested spec', () => true);
});
@mmrko
mmrko / git-zsh-checkout-autocomplete-local-only.md
Last active July 20, 2023 08:48
List only local branches when autocompleting git checkout (Zsh)
git config --global alias.checkoutr checkout
$EDITOR /usr/local/share/zsh/site-functions/git-completion.bash

...and then modify the file as follows...

-__gitcomp_nl "$(__git_refs '' $track)"
+if [ "$command" = "checkoutr" ]; then
+    __gitcomp_nl "$(__git_refs '' $track)"
+else
@bspkrs
bspkrs / pg_change_schema_owner.sh
Last active September 18, 2023 23:26 — forked from mintsoft/change_db_owner.sh
Changes the owner on all tables, sequences, views, and functions in a PostgreSQL database with support for identifiers with whitespace and non-public schemas.
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
This script sets ownership for all tables, sequences, views, and functions for a given schema.
Run this script as your postgres OS user.
@gdamjan
gdamjan / README.md
Last active June 3, 2024 06:48
Setup for an easy to use, simple reverse http tunnels with nginx and ssh. It's that simple there's no authentication at all. The end result, a single ssh command invocation gives you a public url for your web app hosted on your laptop.

What

A lot of times you are developing a web application on your own laptop or home computer and would like to demo it to the public. Most of those times you are behind a router/firewall and you don't have a public IP address. Instead of configuring routers (often not possible), this solution gives you a public URL that's reverse tunnelled via ssh to your laptop.

Because of the relaxation of the sshd setup, it's best used on a dedicated virtual machine just for this (an Amazon micro instance for example).

Requirements

@gkop
gkop / gist:3921201
Created October 19, 2012 23:03
Ruby's "and" and "or" operators explained

|| and && bind with the precedence that you expect from boolean operators in programming languages (&& is very strong, || is slightly less strong).

and and or have lower precedence.

For example, unlike ||, or has lower precedence than =:

> a = false || true
 => true 
> a

=> true

@GerHobbelt
GerHobbelt / .gitignore
Created September 9, 2012 08:04
d3.js: using tree layout for graphs which have nodes with multiple 'parents'
# Editor backup files
*.bak
*~
@iain
iain / gist:2563017
Created April 30, 2012 21:58
global variables in Ruby and the 'english' extension
>> global_variables
=> [:$;, :$-F, :$@, :$!, :$SAFE, :$~, :$&, :$`, :$', :$+, :$=, :$KCODE, :$-K, :$,, :$/, :$-0,
:$\, :$_, :$stdin, :$stdout, :$stderr, :$>, :$<, :$., :$FILENAME, :$-i, :$*, :$?, :$$, :$:,
:$-I, :$LOAD_PATH, :$", :$LOADED_FEATURES, :$VERBOSE, :$-v, :$-w, :$-W, :$DEBUG, :$-d, :$0,
:$PROGRAM_NAME, :$-p, :$-l, :$-a, :$binding, :$1, :$2, :$3, :$4, :$5, :$6, :$7, :$8, :$9]
>> require 'english'
=> true
>> global_variables