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
| #!/bin/bash | |
| files="*.mp4" | |
| regexp="([0-9]+).mp4" | |
| for i in $files | |
| do | |
| if [[ $i =~ $regexp ]] | |
| then | |
| idx="${BASH_REMATCH[1]}" | |
| name=$(printf "%02d" $idx) |
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 'pg' | |
| conn = PG::Connection.open ENV['DATABASE_URL'] | |
| Dir.glob("tmp/exports/*.copy").sort.each do |f| | |
| puts "#{Time.now} - batch #{f} ..." | |
| rs = conn.copy_data "COPY some_table FROM STDOUT" do | |
| File.open(f).each_line do |ln| | |
| conn.put_copy_data ln | |
| 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
| CREATE TABLE categories ( id integer ); | |
| CREATE TABLE products ( id integer, cat_id integer ); | |
| INSERT INTO categories(id) VALUES(1); | |
| INSERT INTO categories(id) VALUES(2); | |
| INSERT INTO products(id, cat_id) VALUES(1, 1); | |
| SELECT c.id, count(1) FROM categories c |
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
| def test_something(mocker): | |
| session = requests.Session() | |
| resp = requests.Response() | |
| resp._content = "response_body" | |
| resp.status_code = 200 | |
| resp2 = requests.Response() | |
| resp2._content = '{"results":[]}'.encode('utf-8') | |
| resp2.status_code = 200 | |
| mocker.patch.object(session, 'get', side_effect=[resp, resp2]) | |
| mocker.patch('requests.Session', return_value=session) |
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
| import socket | |
| s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| s.connect(("8.8.8.8", 80)) | |
| print(s.getsockname()[0]) | |
| s.close() | |
| # https://stackoverflow.com/a/166589 |
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
| >>> def hi(): | |
| ... def h2(): | |
| ... print('h2') | |
| ... h2() | |
| ... | |
| >>> hi() | |
| h2 | |
| >>> h2() | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> |
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
| version: '2' | |
| services: | |
| postgres: | |
| image: postgres:9.6 | |
| ports: | |
| - "5432:5432" | |
| environment: | |
| POSTGRES_PASSWORD: a |
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
| SELECT nspname || '.' || relname AS "relation", | |
| pg_size_pretty(pg_relation_size(C.oid)) AS "size" | |
| FROM pg_class C | |
| LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |
| WHERE nspname NOT IN ('pg_catalog', 'information_schema') | |
| ORDER BY pg_relation_size(C.oid) DESC | |
| LIMIT 200 -- bigtables; | |
| SELECT | |
| pg_stat_activity.pid, |
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
| before_fork do | |
| trap 'TTIN' do | |
| Thread.list.each do |thread| | |
| puts "\nThread TID-#{thread.object_id.to_s(36)}" | |
| puts thread.backtrace.join("\n") | |
| puts "\n" | |
| end | |
| end | |
| 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
| " Copy from Vim to clipboard | |
| vmap <leader>x :w! ~/.vbuf<cr>:!cat ~/.vbuf \| xclip -in -sel clip<cr><cr> | |
| " Strip rspec outputs | |
| :%s/rspec \(.\{-}\) #.\+/\1 \\/gc |