Skip to content

Instantly share code, notes, and snippets.

View konjoot's full-sized avatar

Sergey Maksimov konjoot

View GitHub Profile
@konjoot
konjoot / list-tables-by-size.sql
Last active November 27, 2018 14:35
List tables sorted by size with rows count by schema (PostgreSQL only)
SELECT table_name,
pg_relation_size(quote_ident(table_name)) AS size,
n_live_tup AS rows
FROM information_schema.tables AS it
JOIN pg_stat_user_tables AS ut
ON it.table_name = ut.relname
AND it.table_schema = ut.schemaname
WHERE table_schema = 'public'
ORDER BY 2 DESC;
@konjoot
konjoot / openssl-export.sh
Created June 8, 2018 14:27
openssl export certs from pfx bundle
# Export client certificate
openssl pkcs12 -in bundle.pfx -clcerts -nokeys -out client.pem
# Export client key
openssl pkcs12 -in bundle.pfx -nocerts -out client.key -nodes
# Export CA certs chain
openssl pkcs12 -in bundle.pfx -cacerts -nokeys -out ca.pem
@konjoot
konjoot / docker_reset.sh
Created March 22, 2018 11:43
Docker full reset. Removes all docker containers, images, networks and volumes
#!/usr/bin/env bash
RUNNING_CONTAINERS=`docker ps -aq`
if [[ $RUNNING_CONTAINERS ]]; then
docker stop $RUNNING_CONTAINERS
docker rm -f $RUNNING_CONTAINERS
fi
docker network prune -f
@konjoot
konjoot / main.go
Last active January 4, 2018 09:47
Print negative powers
package main
import (
"flag"
"fmt"
"os"
)
func main() {
@konjoot
konjoot / main.go
Last active January 4, 2018 09:47
Safe mod
package main
import "fmt"
func main() {
for a, b := range map[int]int{
-1: 100,
-101: 100,
245: 100,
@konjoot
konjoot / gist:458ee3e72fe34764d47b
Created January 29, 2015 12:35
schema_plus buggy migration
class Migration < ActiveRecord::Migration
def change
SchemaPlus.setup do |config|
config.foreign_keys.auto_create = false
end
create_table :period_types, force: true do |t|
t.string :name
end
@konjoot
konjoot / capybara_find_hidden_elems.rb
Created October 23, 2013 16:13
Configure Capybara 2.1.0 to find invisible elements
Capybara.configure do |config|
config.match = :prefer_exact
config.ignore_hidden_elements = false
end
@konjoot
konjoot / ubuntu_chrome.sh
Created October 23, 2013 16:11
Google Chrome in Ubuntu
# Ubuntu installation instructions for Google Chrome
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install google-chrome-stable
@konjoot
konjoot / chrom_selenium_capybara_setup.rb
Last active December 26, 2015 08:19
Capybara 2.1.0 + Selenium 2.37.0 with Chrome webdriver
# 1. install Google Chrome
# 2. download latest Google Chrome webdriver from there: http://chromedriver.storage.googleapis.com/index.htm
# 3. unzip and copy to /usr/local/bin
# 4. setup rights for your user and make it executable
# 5. setup Selenium and Capybara
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end