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
# model file | |
class User < ActiveRecord::Base | |
has_many :books | |
accepts_nested_attributes_for :books, :reject_if => lambda {|book| book[:name].blank? }, :allow_destroy => true | |
end | |
# :reject_if => it passes the whole hash passed from browser with book details into this Proc(lambda) and iterates over each book hash. The book record is not created if the condition given in the lambda block is satisfied. | |
# :allow_destroy => if set to true, then the book record that was passed from browser, while submitting User form, with a key-value pair :_destroy => 1 (or '1' or true or "true") will be destroyed |
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
package migration | |
type Migrator interface { | |
Migrate() error | |
} |
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
# cd to the folder where you have your .mov video files. | |
find . -name \*.mov -print0 | xargs -0 -I{} ffmpeg -i {} -f mp4 -vcodec libx264 -preset fast -profile:v main -acodec aac -vf scale=1024:576 {}.mp4 |
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
{ | |
'type': 'RGB' | |
'bandInfo': { | |
0 : { 'type': '...', 'colorinterpreter': 'R' } | |
1 : { 'type': '...', 'colorinterpreter': 'G' } | |
} | |
'cogInfo': {} | |
'mapTile': {} | |
} |
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
FROM python:3.6-slim-stretch | |
ADD requirements.txt /tmp/requirements.txt | |
RUN apt-get update && \ | |
apt-get install -y \ | |
build-essential \ | |
make \ | |
gcc \ | |
locales \ |
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
package models_test | |
import ( | |
"testing" | |
"github.com/stretchr/testify/assert" | |
) | |
func TestMeta_ToJson(t *testing.T) { | |
assert := assert.New(t) |
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 variables with @ are accessible from class methods! | |
class MyClass | |
@var = 2 | |
def self.square | |
@var *= @var | |
end | |
end | |
MyClass.square |
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
docker build -t pandas_app:latest . |
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
# * 100,000,000-line file generated by seq 100000000 > test.in | |
# * Reading lines 50,000,000-50,000,010 | |
# * Tests in no particular order | |
# * real time as reported by bash's builtin time | |
# https://unix.stackexchange.com/questions/47407/cat-line-x-to-line-y-on-a-huge-file | |
awk 'NR >= 57890000 && NR <= 57890010' /path/to/file | |
awk 'NR < 57890000 { next } { print } NR == 57890010 { exit }' /path/to/file | |
tail -n+50000000 test.in | head -n10 |
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
req = RestClient::Request.new(url: "www.google.com", method: 'get') | |
net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK") | |
net_http_resp.add_field 'Set-Cookie', 'Monster' | |
resp = RestClient::Response.create(response_body.to_json, net_http_resp, req) |
NewerOlder