Skip to content

Instantly share code, notes, and snippets.

View matthaliski's full-sized avatar
🏠
Building stuff.

Matt Haliski matthaliski

🏠
Building stuff.
View GitHub Profile
@matthaliski
matthaliski / post.rb
Last active January 18, 2016 22:42
Editing a form using fields_for in Rails
# app/models/post.rb
class Post < ActiveRecord::Base
has_many :tags, dependent: :destroy
# Enable the building of complex forms
accepts_nested_attributes_for :tags, allow_destroy: true
end
@matthaliski
matthaliski / gist:419faf08c77d258d4224
Created September 29, 2014 14:42
Fix for -> PG::Error: ERROR: duplicate key value violates unique constraint
# 'users' is whatever table you need to fix.
# http://stackoverflow.com/questions/13670235/after-importing-data-in-postgresql-duplicate-key-value-violates-unique-constrai

ActiveRecord::Base.connection.reset_pk_sequence!('users')
@matthaliski
matthaliski / gist:ab24a670f0b35316d1d7
Last active August 29, 2015 14:02
Testing for admin role using Devise

Create your devise User model

We start by getting devise up and running and generating the User model.

rails generate devise User

Then you'll probably run rake db:migrate and follow their instructions for making sure you have a few default things in order. Okay, so far so good.

Add a role column to Users

@matthaliski
matthaliski / gist:10290892
Last active August 29, 2015 13:58
Click Tags

Basic vanilla clickTag that should work everywhere.

Note: you'll probably end up with IE giving you the butter bar.

function basicClickTag(e:MouseEvent):void { 
	flash.net.navigateToURL( 
		new URLRequest(root.loaderInfo.parameters.clickTAG), '_blank' );
} 
@matthaliski
matthaliski / RailsTesting.md
Last active December 19, 2015 09:49
Rails Testing

Rails Testing

Below are some tools, workarounds, and gotchas to help speed things up when getting testing working.

Capybara


To get tests to run properly you'll need to add a line to spec_helper.rb file.

.
.
@matthaliski
matthaliski / gist:4253339
Last active July 11, 2016 19:35
How to Post to a Google Spreadsheet

How to Post to a Google Spreadsheet

Part 1 - Setting up the Google Document

  • Go to Google Docs and create your spreadsheet
  • Give column names and make note of them as they become the names of your input fields
  • Give the spreadsheet the tab name of "DATA"
  • Click Tools > Script Editor
  • Choose 'Spreadsheet' under 'Create Script for'
@matthaliski
matthaliski / WordPress Admin Column Views
Created May 24, 2012 21:31
Column Views for Wordpress
//Define the colums we want to see in the work view
add_filter("manage_edit-work_columns", "work_edit_columns");
function work_edit_columns($columns)
{
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Project",
"client" => "Client",
"disciplines" => "Disciplines",
"comments" => "<img alt='Comments' src='http://matthaliski.com/wp-admin/images/comment-grey-bubble.png'>",
@matthaliski
matthaliski / StageListener.as
Last active October 5, 2015 08:28
Listens for the stage
//It's a good idea to listen for the stage before you attempt to access it
if (stage) {
init();
} else {
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
@matthaliski
matthaliski / DefineSwf.as
Last active October 5, 2015 08:28
Define swf properties in ActionScript only projects
//There is no need to hook up to a pointless FLA in larger projects. Just define your swf properties like this
//Included in the Document Class within the package.
[SWF(width='160',height='600',backgroundColor='#000000',frameRate='24')]