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
# Example INSERT INTO with ON CONFLICT behavior | |
SAVED_FIELDS="state, name, type, instance_id, public_ip, launch_time, region, profile, publicdnsname" | |
row='{"state":"running","name":"important_key_name","type":"t2.medium","instance_id":"i-0a1b2c3d4e556677f","public_ip":"11.111.1.111","launch_time":"2019-01-30T08:00:00.000Z","region":"eu-central-1","profile":"","publicdnsname":"ec2-xx-xxx-x-x.eu-central-1.compute.amazonaws.com"}' | |
DATABASE="aws_instances" | |
TABLE_NAME="aws_ec2" | |
psql -c "INSERT INTO $TABLE_NAME($SAVED_FIELDS) SELECT $SAVED_FIELDS from json_populate_record(NULL::$TABLE_NAME, '${row}') | |
ON CONFLICT (instance_id) | |
DO UPDATE |
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
function randomString() { | |
return Math.floor((1 + Math.random()) * 0x10000).toString(32) | |
} | |
const randomId = () => (`${randomString()}-${randomString()}-${randomString()}`) |
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
module Probability | |
def binomial(n, k) | |
return 1 if k == 0 || n == k | |
if n < 0 || k < 0 | |
raise ArgumentError, 'both arguments must be greater than 0' | |
elsif k >= n | |
raise ArgumentError, 'second argument can\'t be greater than first one' | |
end |
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
# Sonic Pi Diggy diggy hole chorus based on https://musescore.com/user/1121936/scores/1022696 | |
# :Ab, :Bb, :Db, :Eb | |
define :play_note do |note| | |
play note[0], release: note[1] | |
sleep note[1] | |
end | |
loop do | |
[ |
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
# For mac XOS | |
# dependent from SetFile | |
# uses it like: SetFile -d '12/31/1999 23:59:59' photo.jpg in order to change | |
# the displayed creation date of a file | |
# usage: enter directory with all directories with names, which are date-like | |
# yyyymmdd - so y - year; m - month; d - day | |
# 1. put file on the desktop | |
# 2. enter irb | |
# 3. write in console: load '~/Desktop/change_exifs.rb' |
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
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'activerecord', '4.2.1' | |
gem 'state_machines' | |
gem 'sqlite3' | |
gem 'minitest' | |
GEMFILE | |
system 'bundle' |