Check your terminal for next steps 👀
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 sometimes_fails | |
| puts "Beginning of sometimes_fails" | |
| begin | |
| retries ||= 0 | |
| puts "About to do a thing (#{retries})" | |
| raise StandardError if rand(5) != 4 | |
| puts "Success!" |
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
| class Thing | |
| def initialize(value) | |
| @value = value | |
| end | |
| def call(other_value) | |
| @other_value = other_value | |
| puts final_value | |
| 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
| function switch_pg { | |
| local version_to_run=$1 | |
| local currently_running_version=$(psql --no-psqlrc -t -c 'show server_version;' postgres | xargs) | |
| # check if you're erroneously switching to the same version | |
| if [ "$version_to_run" = "$currently_running_version" ]; then | |
| echo "Postgres $version_to_run is already running." | |
| return 1 | |
| fi |
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 temp table with sample input | |
| insert into xmas_data (value) values (35), (20), (15), (25), (47), (40), (62), (55), (65), (95), (102), (117), (150), (182), (127), (219), (299), (277), (309), (576); | |
| -- starter subquery | |
| select | |
| v1.id v1id, | |
| v2.id v2id, | |
| v1.value, | |
| v2.value, | |
| v1.value + v2.value sum |
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 "golang.org/x/tour/pic" | |
| func Pic(dx, dy int) [][]uint8 { | |
| var picArray [][]uint8 | |
| picArray = make([][]uint8, 0, dy) | |
| for i := 0; i < dy; i++ { | |
| var currX []uint8 | |
| currX = make([]uint8, 0, dx) |
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
| defmodule PipeInspect do | |
| # | |
| # Usage: | |
| # | |
| # Instead of temporarily breaking up a series of pipes to inspect the values: | |
| # ``` | |
| # partial_result = | |
| # 1..100_000 | |
| # |> Enum.map(&(&1 * 3)) | |
| # |
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
| > string1 = "\u0065\u0301" | |
| "é" | |
| > string2 = "é" | |
| "é" | |
| > string1 == string2 | |
| false | |
| > String.codepoints(string1) | |
| ["e", "́"] | |
| > String.codepoints(string2) | |
| ["é"] |
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
| # Sorting Rows By Index | |
| Welcome back to pgcasts, my name is Josh Branchaud. In this episode I am going to talk about a handy shortcut we can use when ordering rows in a select statement. | |
| Let's say we have a users table: | |
| ```sql | |
| create table users ( | |
| id serial primary key, | |
| first varchar not null, |
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 'date' | |
| require 'minitest/autorun' | |
| class TestMeme < MiniTest::Unit::TestCase | |
| def time_to_timestamp(now:) | |
| hours_in_seconds = now.strftime('%H').to_i * 3600 | |
| minutes_in_seconds = now.strftime('%M').to_i * 60 | |
| seconds = now.strftime('%S').to_i |