Skip to content

Instantly share code, notes, and snippets.

Avatar

Scott Watermasysk scottwater

View GitHub Profile
View audit.rb
before_update :audit
def audit
if self.changed?
# find columns we want to audit
audit_columns = UserAudit.column_names.reject{|c| %w{id created_at updated_at}.include?(c)}
# add the user_id
data = self.attributes.dup.merge('user_id' => self.id)
# copy the pre-modified values
self.changes.each {|att, a| data[att] = a[0]}
@scottwater
scottwater / estimate_count.rb
Created Mar 26, 2014
Get a rough count on the number of records in a postgres table via active record.
View estimate_count.rb
module EstimateCount
extend ActiveSupport::Concern
module ClassMethods
def estimate_count
sql = "SELECT reltuples FROM pg_class WHERE relname = '#{self.table_name}'"
query = self.connection.execute(sql)
if result = query.first
("%f" % result['reltuples']).to_i
@scottwater
scottwater / gist:9782993
Last active Aug 29, 2015
How to find the perfect vim theme
View gist:9782993
Quick tips for finding the perfect theme for vim.
1. Install flazz/vim-colorschemes plugin (480+ themes)
You can see previews here: http://vimcolorschemetest.googlecode.com/svn/html/index-html.html
Too many for me to look through...plus, how does it look with my code?
2. Set your colorscheme to random
View utm_values.js
<script>
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
{return null;}
@scottwater
scottwater / footer.html
Created Aug 7, 2014
Post SIgn-Up Redirect
View footer.html
@scottwater
scottwater / phone.html
Created Aug 25, 2014
KickoffLabs Phone Number Support
View phone.html
<script src="//s3.amazonaws.com/assets.kickofflabs.com/js/jquery.maskedinput.min.js"></script>
<script>
jQuery(function($){
$("[name^='phone']").mask("(999) 999-9999");
});
</script>
@scottwater
scottwater / Widget Event
Created Jun 30, 2015
KickoffLabs Widget Success Event
View Widget Event
<script type="text/javascript">
$(document).ready(function(){
$(document).bind("kol:success", function(e, data, status, xhr) {
});
});
</script>
View Document.cs
/*
* User: scorder
* Date: 7/8/2009
*
* Updated: 2/1/2010
* User: scottwater
* Minor changes to Document to make it play nicely with
* C# 4.0 dynamics
*/
using System;
View Post.cs
public class Post
{
public virtual int Id { get; set; }
public virtual string Title { get; set; }
public virtual string Body { get; set; }
public virtual DateTime PubDate { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
}
View demo_app.rb
require 'rubygems'
require 'sinatra'
require 'consistenturls'
#plugin
validate_url_requests
get '/' do
"Hello World"
end
You can’t perform that action at this time.