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
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 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
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
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
#!/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
package main | |
import ( | |
"fmt" | |
) | |
type A struct{} | |
func (A) hi() string { | |
return "hi 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
# fix keyboard | |
echo 0 > /sys/module/hid_apple/parameters/iso_layout | |
# prevent wakeup from usb | |
echo XHC1 > /proc/acpi/wakeup | |
exit 0 |
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
// https://play.golang.org/p/CpPW7CxYBV | |
package main | |
import ( | |
"fmt" | |
) | |
type A struct { | |
X string |
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
package main | |
import ( | |
"fmt" | |
"testing" | |
) | |
func BenchmarkAppendFloat(b *testing.B) { | |
benchmarks := []int{10, 100, 1000, 10000, 1e5} | |
for _, bm := range benchmarks { |