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
| # Example of using | |
| require 'sqlite3' | |
| require 'active_record' | |
| ActiveRecord::Base.establish_connection("sqlite3::memory:") | |
| conn = ActiveRecord::Base.connection | |
| conn.create_table :users do |t| | |
| t.string :name | |
| end | |
| conn.create_table :user_matches do |t| | |
| t.references :sender |
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
| #!/usr/bin/env python3 | |
| """ | |
| Script to update this host's DNS entry on Cloudflare. Silently succeeds. | |
| It requires you to have set the environment variables: | |
| - CLOUDFLARE_API_KEY | |
| - CLOUDFLARE_EMAIL | |
| - CLOUDFLARE_HOSTNAME |
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
| #!/usr/bin/env sh | |
| name="My Cool Web App Project" | |
| serve="npm start" | |
| watch="node_modules/.bin/cake watch" | |
| serve="npm start" | |
| tmux has-session -t "$name" | |
| if [ $? != 0 ] | |
| then |
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 ( | |
| "bytes" | |
| "fmt" | |
| "io/ioutil" | |
| "net/http" | |
| "testing" | |
| ) | |
| type incrt byte |
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/sh | |
| # This program shows the result of applying the % and # shell parameter | |
| # expansion modifiers to a parameter, for those who are constantly looking it | |
| # up. | |
| x=${1:?Usage: parmexp <parameter>} | |
| echo "(hash dot star) ‥‥‥‥‥‥‥‥....... $x \${x#.*} → ${x#.*}" | |
| echo "(hash hash dot star) .......... $x \${x##.*} → ${x##.*}" | |
| echo "(percent dot star) ............ $x \${x%.*} → ${x%.*}" |
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
| /* | |
| * Converts the 2-letter code (such as "es" or "ie" to an emoji representing that country's flag. | |
| * It works because a flag emoji, such as the German flag, is a combination of regional letter | |
| * glyphs (🇩 🇪 without a space is rendered as 🇩🇪, the German (de) flag). Those glyphs start at | |
| * 0x1f1e6 and end at 0x1f1ff. 'a' is 97. | |
| */ | |
| const flagEmojiForCode = (code) => { | |
| const h = code.toLowerCase().charCodeAt(0) + (0x1f1e6 - 97) | |
| const l = code.toLowerCase().charCodeAt(1) + (0x1f1e6 - 97) | |
| return String.fromCodePoint(h, l) |
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
| ; A functional solution to Uncle Bob's Bowling Game | |
| ; https://programmingpraxis.com/2009/08/11/uncle-bobs-bowling-game-kata/ | |
| (defun strike? (roll) | |
| (and roll | |
| (= 10 (first roll)))) | |
| (defun spare? (roll) | |
| (and roll | |
| (rest roll) |
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 'minitest/autorun' | |
| # A Ruby solution to Uncle Bob's Bowling Game | |
| # https://programmingpraxis.com/2009/08/11/uncle-bobs-bowling-game-kata/ | |
| module Bowling | |
| module_function | |
| def strike?(scores) | |
| scores&.first == 10 |
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
| #!/usr/bin/env python | |
| from enum import Enum, IntEnum | |
| from typing import Dict, Callable | |
| import unittest | |
| class Direction(IntEnum): | |
| NORTH = 0 | |
| EAST = 1 |
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
| # awsume | |
| # Usage: awsume ROLENAME | |
| # It uses the _current_ AWS profile (set as an env-var or the default) to get | |
| # the user's ARN and associated MFA devices, then it asks for a token code, | |
| # sends the `aws sts assume-role` call to AWS, and exports the resulting session. | |
| # /usr/bin/env bash | |
| awsume() { | |
| user="$(aws sts get-caller-identity --query 'Arn' --output text)" | |
| role="${user%:*}:role/${1?Usage: $0 profile}" |