Skip to content

Instantly share code, notes, and snippets.

Avatar

Joel Berghoff bergonom

View GitHub Profile
@bergonom
bergonom / truncate_table.rb
Created Mar 15, 2013
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: https://gist.github.com/tvdeyen/3246525
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
bergonom / custom_inputs.css
Created Jan 24, 2013
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: http://www.inserthtml.com/2012/06/custom-form-radio-checkbox
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
bergonom / example.php
Created Aug 4, 2011
A simple Postmark PHP Class
View example.php
<?php
require("postmark.php");
$postmark = new Postmark("your-api-key","from-email","optional-reply-to-address");
if($postmark->to("reciver@example.com")->cc('ccreciever@example.com')->bcc('bccreciever@example.com')->subject("Email Subject")->plain_message("This is a plain text message.")->send()){
echo "Message sent";
}