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
## rails g migration add_timestamps | |
## Insert the following, with whatever version of ActiveRecord you're using. | |
class AddTimestamps < ActiveRecord::Migration[5.0] | |
def change | |
ActiveRecord::Base.connection.tables.each do |table_name| | |
columns = ActiveRecord::Base.connection.columns(table_name).map { |c| c.name } | |
["created_at", "updated_at"].each do |timestamp| | |
unless columns.include?(timestamp) | |
add_column table_name, timestamp, :datetime |
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
# You'll probably want to Ctrl+C out of this one pretty quickly. | |
File.open($0, "r+") do |f| | |
content = f.read | |
puts content | |
f << content | |
f.close | |
sleep 5 | |
system "ruby", $0 |
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
$styles: margin padding; | |
$directions: left right top bottom; | |
@each $style in $styles { | |
@for $i from 0 through 50 { | |
.#{$style}-#{$i} { #{$style}: #{$i}px; } | |
@each $direction in $directions { | |
.#{$style}-#{$direction}-#{$i} { #{$style}-#{$direction}: #{$i}px } | |
} | |
} |
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
(1..100).each do |i| | |
[3, 5].each do |num| | |
define_method("klass_#{num}") do | |
Class.new do | |
if i % num == 0 | |
define_method("#{i}") do | |
call | |
end | |
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
# Based on https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange | |
require "prime" | |
require "openssl" | |
class Client | |
def initialize | |
@private_key = rand(1..100000) | |
@clients = {} | |
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
#!/bin/zsh | |
# Backup a folder to a remote address using borg. | |
# To restore: borg extract $BORG_REPO::computer-and-date | |
set -eu | |
# Will need a remote server setup with Borg, and a Borg repo first. | |
export BORG_REPO="<user>@<host>:<borg-repo>" | |
# Assuming you've installed Borg with Homebrew |
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 stop $(docker ps -qa); docker rm $(docker ps -qa); docker rmi -f $(docker images -qa); docker volume rm $(docker volume ls -q); docker network rm $(docker network ls -q) |
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
# https://thomasleecopeland.com/2017/04/20/shadowing-bug-in-the-wild.html | |
# https://docs.ruby-lang.org/en/2.4.0/syntax/assignment_rdoc.html#label-Local+Variables+and+Methods | |
# https://www.codinginthecrease.com/news_article/show/307337 | |
class Okay | |
def yep | |
"yep" | |
end | |
def nope |
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
#!/bin/sh | |
# Add or `ln -s` this into `/usr/local/bin/` | |
echo "Updating everything..." | |
echo "Updating Homebrew and all Homebrew packages" | |
brew update && brew upgrade && brew cleanup && brew doctor | |
echo "Updating all programming languages" |