This file contains 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
class Thread::Simple | |
attr_accessor :que, :size, :named | |
def initialize size: 5, sleep: 0.01 | |
@sync = Mutex.new | |
@sleep = sleep | |
@size = size | |
@que = [] | |
@threds = [] | |
@named = {} |
This file contains 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
# asciinema rec --overwrite tmp/demo.case | |
# bash demo.bash | |
type_and_run () { | |
printf '\033[01;37m@app $\033[0m ' | |
for ((i=0; i<${#1}; i++)); do echo "after `jot -r 1 20 60`" | tclsh; printf "${1:$i:1}"; done; | |
echo; | |
$1; | |
echo; | |
} |
This file contains 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
# Defines class variable | |
def Object.class_attribute name, default=nil, &block | |
raise ArgumentError.new('name must be symbol') unless name.class == Symbol | |
ivar = "@cattr_#{name}" | |
instance_variable_set ivar, block || default | |
define_singleton_method(name) do |arg=:_undefined| | |
# define and set if argument given |
This file contains 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 | |
class FolderModel | |
class << self | |
def find(key) | |
new(key) | |
end | |
def all |
This file contains 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
# Rails style callbacks | |
# for controllers, execute from AppController to MainController | |
# class_callback :before | |
# before do | |
# ... | |
# end | |
# before :method_name | |
# instance = new | |
# Object.class_callback :before, instance |
This file contains 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
# call just after body tag or $ -> window.MediaBodyClass.init() | |
# sets body class for | |
# mobile to "mobile not-tablet not-desktop" | |
# tablet to "not-mobile tablet not-desktop" | |
# desktop to "not-mobile not-tablet desktop" | |
@MediaBodyClass = | |
sizes: [['mobile'], ['tablet', 767], ['desktop', 1023]] | |
init: -> |
This file contains 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
menu = HtmlMenu.new request.path | |
menu.add 'Home', '/' | |
menu.add 'People', '/people', lambda { |path| path.index('peor') } | |
menu.add 'Jobs', '/jbos' | |
menu.to_a -> [["Home", "/", false], ["People", "/people", true], ["Jobs", "/jbos", false]] | |
menu.to_h -> [{:name=>"Home", :path=>"/", :active=>true}, {:name=>"People", :path=>"/people", :active=>false}, {:name=>"Jobs", :path=>"/jbos", :active=>false}] |
This file contains 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 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 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 |