Skip to content

Instantly share code, notes, and snippets.

View bergonom's full-sized avatar

Joel Berghoff bergonom

View GitHub Profile
bergonom / truncate_table.rb
Created March 15, 2013 22:43
Truncate a single table across multiple db types. I made this a private method in my application controller (app/controllers/application_controller.rb). Adapted from:
View truncate_table.rb
def truncate_table table_name
config = Rails.configuration.database_configuration
connection = ActiveRecord::Base.connection
connection.disable_referential_integrity do
next if connection.select_value("SELECT count(*) FROM #{table_name}") == 0
case config[Rails.env]["adapter"]
when "mysql", "mysql2", "postgresql"
connection.execute("TRUNCATE #{table_name}")
when "sqlite", "sqlite3"
connection.execute("DELETE FROM #{table_name}")
bergonom / custom_inputs.css
Created January 24, 2013 20:47
Update to CSS for creating custom checkboxes and radio buttons. This CSS will allow the input elements to show that they have focus when the user accesses tabs through form elements. See the original article here:
View custom_inputs.css
/* Hide the checkbox offscreen */
.regular-checkbox {
display: inline;
left: -8000px;
position: fixed;
/* Highlight the custom checkbox's border when the checkbox has focus. */
.regular-checkbox:focus + label {
border: 1px solid #000;
bergonom / example.php
Created August 4, 2011 10:22
A simple Postmark PHP Class
View example.php
$postmark = new Postmark("your-api-key","from-email","optional-reply-to-address");
if($postmark->to("")->cc('')->bcc('')->subject("Email Subject")->plain_message("This is a plain text message.")->send()){
echo "Message sent";