Skip to content

Instantly share code, notes, and snippets.

View charlespeach's full-sized avatar

Charles Peach charlespeach

View GitHub Profile
namespace :associate_users do
desc "Update users external builder" do
@users = User.where(:external_builder_id => nil)
@users.each do |user|
#associate ExternalBuilder with User
unless user.lbp_number.blank?
@builder = ExternalBuilder.where(:lbp_number => user.lbp_number.gsub("BP", "").to_i)
if !@builder.blank?
u.update_column(:external_builder_id, @builder)
end
@charlespeach
charlespeach / sendmail.md
Last active December 15, 2015 18:58
Just some useful stuff for sendmail

Sendmail

Checking Queue

sendmail -bp or mailq

to check whats in the sendmail queue

# gem "prawn", "0.8.4"
# Sometime there is no enough space for the last table row when it reaches the end of page
Prawn::Document.generate("text_group_overflow_question.pdf") do |pdf|
add_page_break_if_overflow(pdf) do |pdf|
# generating table here
# ...
end
end
@charlespeach
charlespeach / install_gems.rb
Created July 9, 2013 03:38
Install a list of gems from a `.gems` file.
gems = File.open(".gems")
gems.each do |gem|
puts "Installing #{gem}"
`gem install #{gem}`
end
@charlespeach
charlespeach / clear_rails_sessions.md
Last active December 19, 2015 22:08
How to clear sessions in rails

Resetting user sessions

First check what type of session store your application is setup for

This config usually lives here: config/initializers/session_store.rb

ApplicationName::Application.config.session_store :cookie_store, key: '_application_name_session'
/*
* Scaffolding
* Basic and global styles for generating a grid system, structural layout, and page templates
* ------------------------------------------------------------------------------------------- */
.container
Sets a width of 940px which also centres the content (clears floated elements before/after)
.container-fluid
Sets a minimum width of 940px (clears floated elements before/after)
@charlespeach
charlespeach / readonly_db_access.sh
Last active August 29, 2015 13:57
Grant select access to a user for all tables in a postgres database
#!/bin/sh
tables=$(psql database_name -A -t -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';")
for table in $tables
do
echo "Granting select to username on $table"
psql database_name -c "GRANT SELECT ON $table to username;"
done
@charlespeach
charlespeach / gist:d6fd4c9349d092b5ec74
Last active August 29, 2015 14:02
PostgreSQL common commands

Atler owner of db

ALTER DATABASE name OWNER TO new_owner;

Create the user

postgres@hostname:~$ createuser
Enter name of role to add: username
@charlespeach
charlespeach / come_to_nz_deadmau5.rb
Last active August 29, 2015 14:02
My feeble attempt to extort a New Zealand visit from @deadmau5 on his next tour using PRINT TORTURE
# Hey @deadmau5, @nz_cub3y here. Wrote this for you.
#
# Running instructions
# ruby come_to_nz_deadmau5.rb
# You can stop the process from running any time using Ctrl+C
# Tour setup
class Tour
attr_accessor :year, :locations
@charlespeach
charlespeach / linux_cheat_sheet
Last active August 29, 2015 14:05
Linux Cheat Sheet
# Add Swap
First check to see if you have swap enabled first `sudo swapon -s`, if not then:
```
sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile none swap sw 0 0 " | sudo tee --append /etc/fstab
echo 10 | sudo tee /proc/sys/vm/swappiness