Skip to content

Instantly share code, notes, and snippets.

View BartlomiejSkwira's full-sized avatar

Bartek Skwira BartlomiejSkwira

View GitHub Profile
To get an overview about how much space is taken by what database, call:
SELECT
pg_database.datname,
pg_size_pretty(pg_database_size(pg_database.datname)) AS size
FROM pg_database;
To get more details, call:
SELECT
relname as "Table",
#macro
Start recording by pressing q, followed by a lower case character to name the macro
Perform any typical editing, actions inside Vim editor, which will be recorded
Stop recording by pressing q
Play the recorded macro by pressing @ followed by the macro name
To repeat macros multiple times, press : NN @ macro name. NN is a number
@BartlomiejSkwira
BartlomiejSkwira / date range overlapping
Created November 14, 2013 11:51
date range intersection
Let ConditionA Mean DateRange A Completely After DateRange B (True if StartA > EndB)
Let ConditionB Mean DateRange A Completely Before DateRange B (True if EndA < StartB)
Then Overlap exists if Neither A Nor B is true ( If one range is neither completely after the other, nor completely before the other, then they must overlap)
Now deMorgan's law says that:
Not (A Or B) <=> Not A And Not B
@BartlomiejSkwira
BartlomiejSkwira / torquebox
Created October 25, 2013 08:24
torquebox
#in Vagrant, bind to 0.0.0.0 automatically
vim /home/vagrant/.rvm/gems/jruby-1.7.4/gems/torquebox-server-2.3.1-java/jboss/standalone/configuration/standalone.xml
#change all bind.address to 0.0.0.0
@BartlomiejSkwira
BartlomiejSkwira / port forward
Created October 24, 2013 07:38
Port forward on Linux
#open port
ufw
#forward
ssh -R 2223:localhost:4567 [email protected]
@BartlomiejSkwira
BartlomiejSkwira / Vagrantfile
Created October 22, 2013 09:47
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
@BartlomiejSkwira
BartlomiejSkwira / hash_empty.js
Last active December 25, 2015 16:29
object/hash is empty
#check support
Object.keys(obj).length === 0
#or
if (Object.getOwnPropertyNames(obj).length > 0) return false;
// Speed up calls to hasOwnProperty
var hasOwnProperty = Object.prototype.hasOwnProperty;
function is_empty(obj) {
@BartlomiejSkwira
BartlomiejSkwira / wait_until.rb
Created October 4, 2013 08:52
wait_until and wait for ajax
# add this file capybara_wait_until.rb to your /test directory
module Capybara
class Session
##
#
# Retry executing the block until a truthy result is returned or the timeout time is exceeded
#
# @param [Integer] timeout The amount of seconds to retry executing the given block
#
@BartlomiejSkwira
BartlomiejSkwira / rest http verbs mapping
Created September 24, 2013 08:43
Rails http response status coded
GET /items #=> index
GET /items/1 #=> show
GET /items/new #=> new
GET /items/1/edit #=> edit
PUT /items/1 #=> update
POST /items #=> create
DELETE /items/1 #=> destroy
@BartlomiejSkwira
BartlomiejSkwira / test.rb
Created September 9, 2013 10:45
environments/test.rb template
Asuitestay::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application