John Grimes johngrimes

View format-mount-fs.sh
1 2 3 4 5 6 7 8 9 10
# Get the device identifier of the device, which is the one that currently does not have a valid partition table.
fdisk -l
 
# Use fdisk to create a new primary Linux partition, which takes up all of the available space.
fdisk /dev/sdb
 
# Make a new ext4 filesystem within the new partition.
mkfs -t ext4 /dev/sdb1
 
# Get the UUID of the new filesystem.
View newsyslog.conf
1 2 3 4 5 6 7
# Put this into /etc/newsyslog.conf, or into a .conf file under /etc/newsyslog.d/
# Format: [logfile_name] [owner:group] [mode] [count] [size] [when] [flags] [path_to_pid_file] [signal_number]
# See https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man5/newsyslog.conf.5.html#//apple_ref/doc/man/5/newsyslog.conf
 
# This trims any log file in this directory that has exceeded 10 MiB in size.
# The G flag allows you to use globbing in the logfile_name field.
/path/to/your/log/files/*.log user:group 640 0 10486 * G
View resync_id_sequences.sql
1 2 3 4 5 6 7 8 9 10
CREATE OR REPLACE FUNCTION resync_id_sequences() RETURNS void AS $$
DECLARE
table RECORD;
sequence_name VARCHAR;
id_present RECORD;
max_id RECORD;
BEGIN
FOR table IN SELECT * FROM information_schema.tables WHERE table_schema = 'public' LOOP
SELECT COUNT(*) AS count INTO id_present
FROM pg_attribute a INNER JOIN pg_class c
View image_optimisation.sh
1 2
find public/images -name '*.png' | xargs optipng
find public/images -name '*.jpg' | xargs jpegoptim
View myapp.conf
1 2 3 4 5 6 7 8 9 10
upstream unicorn-myapp { server 127.0.0.1:3000; }
 
server {
server_name myapp.com;
rewrite ^(.*) http://www.myapp.com$1 permanent;
}
 
server {
listen *:80;
server_name www.myapp.com;
View date.sql
1 2 3 4 5 6 7 8 9 10
/* Adapted from Tom Cunningham's 'Data Warehousing with MySql' (www.meansandends.com/mysql-data-warehouse) */
 
###### small-numbers table
DROP TABLE IF EXISTS numbers_small;
CREATE TABLE numbers_small (number INT);
INSERT INTO numbers_small VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 
###### main numbers table
DROP TABLE IF EXISTS numbers;
CREATE TABLE numbers (number BIGINT);
View deploy.rb
1 2 3 4 5 6 7 8 9 10
require 'bundler/capistrano'
require 'rvm/capistrano'
 
set :application, 'myapp'
 
set :repository, 'git@github.com:johngrimes/myapp.git'
set :scm, 'git'
 
set :bundle_flags, '--deployment'
set :bundle_without, []
View load_seed_data_from_fixtures.rb
1 2 3 4 5 6 7 8 9
namespace :seed_data do
desc 'Load seed data into the database of the current environment'
task :load => :environment do
require 'active_record/fixtures'
Dir.glob(RAILS_ROOT + '/db/seed_data/*.yml').each do |file|
Fixtures.create_fixtures('db/seed_data', File.basename(file, '.*'))
end
end
end
View php_timing.php
1 2 3 4 5 6
$timeStart = microtime(true);
 
/* The code that you want to time */
 
$timeEnd = microtime(true);
$duration = $timeEnd - $timeStart;
View javascript_livevalidation.js
1 2 3
var email = new LiveValidation('email');
email.add(Validate.Presence);
email.add(Validate.Format, { pattern: /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i });
Something went wrong with that request. Please try again.