Skip to content

Instantly share code, notes, and snippets.

View tralston's full-sized avatar

Taylor Ralston tralston

  • Sacramento, CA
  • 15:29 (UTC -07:00)
View GitHub Profile
@tralston
tralston / Problem #1.rb
Last active December 16, 2015 01:49
Project Euler: Problem 1
solution = 0
(1...1000).each do |n|
if n % 3 == 0 or n % 5 == 0
solution += n
end
end
solution
@tralston
tralston / rugygems.sh
Last active December 26, 2015 00:19
Ruby gem commands
# Remove unused gems, clean up broken dependencies
# Use with bundle show <gem> to resolve LoadError problems for gems that are installed but not seen by Rails
gem clean <gem>
# Remove accumulated gem documentation (ri and rdoc)
rm -r `gem env gemdir`/doc
@tralston
tralston / bundler.sh
Created October 21, 2013 18:54
Bundler commands
# List all the gems and versions used in your rails project
bundle show
# Use this to list an individual gem's location. Note that the regular "bundle show" doesn't tell you when a dependency is broken
bundle show <gem>
# Perform "bundle show <gem>" but for all the gems
bundle show | sed -e 's/ \* //g' | sed -e 's/ (.*//g' | xargs -I {} bundle show {}
# Try using bundle install
@tralston
tralston / commands.sh
Last active December 26, 2015 19:39
Bash Commands (Mac OS X)
# Find the MD5 sum of the current directory
find . -type f -not -path "./.git/*" -print0 | xargs -0 md5 | md5
@tralston
tralston / loadscript.js
Created March 21, 2015 13:44
Load external script with a callback to wait for it
$.getScript("http://url/to/javascript.js", function () {
// Do something here. This will be safe to call after asynchronous script load
});
@tralston
tralston / color.gradle
Created March 21, 2015 17:22
Add color to Gradle script
import org.gradle.logging.StyledTextOutput;
import org.gradle.logging.StyledTextOutputFactory;
import static org.gradle.logging.StyledTextOutput.Style;
StyledTextOutput o = services.get(StyledTextOutputFactory).create("test string")
task taskname << {
o.withStyle(Style.Description).append("Hello world!")
// Style.?? Can be normal, header, userinput, identifier, description, progressstatus, failure, info, or error
}
@tralston
tralston / nginx.conf
Created March 21, 2015 17:24
Fix Wordpress permalinks on nginx
#Put this in the nginx.conf file. You may need to add "index index.php" under the server block.
location / {
try_files $uri $uri/ /index.php?$args;
}
@tralston
tralston / curl-ttfb.sh
Created October 28, 2016 22:22 — forked from acdha/curl-ttfb.sh
Use curl to measure and report HTTP response times (pre-, start- and total transfer)
#!/bin/bash
#
# Report time to first byte for the provided URL using a cache buster to ensure
# that we're measuring full cold-cache performance
while (($#)); do
echo $1
curl -so /dev/null -H "Pragma: no-cache" -H "Cache-Control: no-cache" \
-w "%{http_code}\tPre-Transfer: %{time_pretransfer}\tStart Transfer: %{time_starttransfer}\tTotal: %{time_total}\tSize: %{size_download}\n" \
"$1?`date +%s`"
@tralston
tralston / format-json-vim.md
Created August 20, 2017 23:42
[Clean up JSON from vim] #JSON #vim

Usage

:%!python -m json.tool

Requires python to be installed. This command can also be stored in a macro in .vimrc:

function! FormatJSON()
:%!python -m json.tool
endfunction
@tralston
tralston / reload-config-postgresql.md
Created August 21, 2017 08:18
[Reload PostgreSQL config] After updating pg_hba.conf or postgresql.conf, the server needs the config needs to be reloaded. #postgres

After updating pg_hba.conf or postgresql.conf, the server needs the config needs to be reloaded. The easiest way to do this is by restarting the postgres service:

service postgresql restart

When the service command is not available (no upstart on Synology NAS, for example), there are some more creative ways to reload the config. Note this first one needs to be done under the user that runs postgres (usually the user=postgres).

user#  sudo su postgres
postgres#  pg_ctl reload