This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE USER readonly WITH ENCRYPTED PASSWORD 'readonly'; | |
GRANT USAGE ON SCHEMA public to readonly; | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly; | |
-- repeat code below for each database: | |
GRANT CONNECT ON DATABASE foo to readonly; | |
\c foo | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO readonly; --- this grants privileges on new tables generated in new database "foo" | |
GRANT USAGE ON SCHEMA public to readonly; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sequel' | |
require 'securerandom' | |
# DB = Sequel.postgres(...) | |
ch_name = :test_1 | |
Thread.new do | |
DB.listen(ch_name, loop: true) do |channel, pid, payload| | |
p [channel, pid, payload] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tag.ul do |n| | |
# 1.upto(3) do |num| | |
# n.li do |n| | |
# n.i 'arrow' # <i class="arrow"></i> | |
# n._arrow # <div class="arrow"></div> | |
# n.span 123 # <span>123</span> | |
# n.span { 123 } # <span>123</span> | |
# n.('foo') # <div class="foo"></div> | |
# n._foo(bar: baz) { 123 } # <div class="foo" bar="baz">123</div> | |
# end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias ls="command ls -G" | |
alias cp="cp -iv" | |
alias mv="mv -iv" | |
alias mkdir="mkdir -pv" | |
alias less="less -FSRXc" | |
mexe() { touch $1 && chmod +x $1 && subl $1; } # make executable and edit | |
ffl() { find . -name "*$@*"; } # find file local | |
fff() { mdfind -name $1; } # find file global | |
ff() { find . -type d -name "*$@*"; } # find folder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'colorize' | |
# require 'thread/pool' | |
# pool = Thread.pool(3) | |
pool = ThreadPool.new 3 | |
1.upto(10).to_a.each { |num| | |
pool.process do | |
sleep_for = (rand()*10).to_i | |
text = "#{num} sleep #{sleep_for}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# access hash keys with strings or symbols | |
# h = HashWithIndifferentAccess.new a: 1 | |
# h[:a] -> 1 | |
# h['a'] -> 1 | |
class HashWithIndifferentAccess | |
def initialize data=nil | |
@data = {} | |
merge! data if data | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'thor' | |
require 'dotenv' | |
require 'awesome_print' | |
require 'colorize' | |
Dotenv.load | |
def Thor.define name, desc, &block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.copyToClipboard = function(text) { | |
// IE specific | |
if (window.clipboardData && window.clipboardData.setData) { | |
return clipboardData.setData("Text", text); | |
} | |
// all other modern | |
target = document.createElement("textarea"); | |
target.style.position = "absolute"; | |
target.style.left = "-9999px"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'colorize' | |
require 'awesome_print' | |
require 'slop' | |
require 'irb' | |
require 'yaml' | |
module Sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# ClassAttributes.define klass, :layout, 'default_value_optional' | |
# klass.layout -> get value | |
# klass.layout = value -> set value | |
# class A | |
# ClassAttributes.define self, :layout, 'default' | |
# class_attribute :layout, 'default' | |
# end |