Skip to content

Instantly share code, notes, and snippets.

View shawndeprey's full-sized avatar
💭
If you stop learning, you stop living.

Shawn Deprey shawndeprey

💭
If you stop learning, you stop living.
View GitHub Profile
@shawndeprey
shawndeprey / AR in_use? error.rb
Created November 27, 2012 22:05
ActiveRecord in_use? error
undefined method `in_use?' for nil:NilClass
Nov 27, 2012 8:40:01 PM org.apache.catalina.core.ApplicationContext log
SEVERE: Application Error
org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `in_use?' for nil:NilClass
at ActiveRecord::ConnectionAdapters::ConnectionPool.clear_stale_cached_connections!(/var/lib/tomcat7/hosts/app-name-masked.company.net/webapps/specialevents/WEB-INF/gems/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:206)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1615)
at ActiveRecord::ConnectionAdapters::ConnectionPool.clear_stale_cached_connections!(/var/lib/tomcat7/hosts/app-name-masked.company.net/webapps/specialevents/WEB-INF/gems/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:204)
at ActiveRecord::ConnectionAdapters::ConnectionPool.checkout(/var/lib/tomcat7/hosts/app-name-masked.company.net/webapps/specialevents/WEB-INF/gems/gems/activerecord-3.2.6/lib/active_record
package bms;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
@shawndeprey
shawndeprey / gist:910ae2417300703aabd0
Last active August 29, 2015 14:03
Threading Pattern for Request Processing in Rails
def index
Thread.abort_on_exception = true
thr_one = Thread.new do
@list_one = ModelOne.find_model_ones_in_elasticsearch(params[:page])
end
thr_two = Thread.new do
@list_two = ModelTwo.find_model_twos_in_elasticsearch(params[:page])
end
@shawndeprey
shawndeprey / gist:01347d1dd1dfec9b68f2
Created July 30, 2014 16:46
A Helper to Serve Gzip Assets
module GzipHelper
def gzip_javascript_include_tag(asset)
# Grab the asset html include tag
tag = javascript_include_tag asset
# If we are in production and the requesting client accepts gzip encoding, swap for the gzip asset
if Rails.env.production? && request.accept_encoding =~ /gzip/i
tag = tag.gsub(/\.js/i, ".js.gz")
end
class Inquiry < ActiveRecord::Base
include Rakismet::Model
# Create Validator which will hit the Akismet API
class SpamValidator < ActiveModel::Validator
def validate(record)
return true unless record.spam? # record.spam? will hit the Akismet API
record.errors[:base] << "Spam message detected."
end
end
class YourModel < ActiveRecord::Base
include Rakismet::Model
# Create Validator which will hit the Akismet API
class SpamValidator < ActiveModel::Validator
def validate(record)
return true unless record.spam? # record.spam? will hit the Akismet API
record.errors[:base] << "Spam message detected."
end
end
@shawndeprey
shawndeprey / gist:71ab5216906258c768f7
Last active January 31, 2017 10:09
Helper module and class example for type-ahead searching
# Model Mapping example
# Be sure to replicate this with your actual model
class YourModel < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
settings IndexHelper.type_ahead_analysis do
mappings do
indexes :id, index: :no
indexes :screen_name, type: 'string', analyzer: 'autocomplete'
App.ImgView = Ember.View.extend({
tagName: 'img',
attributeBindings: ['src', 'alt', 'onerror'],
defaultPlaceholderImgUrl: "<%= asset_path('kite-client/defaults/default.png') %>",
companyPlaceholderImgUrl: "<%= asset_path('kite-client/defaults/company.png') %>",
onerror: function(){
return "this.onerror=null;this.src='" + this.get('placeholder') + "';"
}.property('src'),
placeholder: function(){
return this.get(this.get('placeholderName') + 'PlaceholderImgUrl') || this.get('defaultPlaceholderImgUrl');
How Arnold Tanks Like a Fucking Beast Warrior
---------------------------------------------
This is pretty much just the standard stuff. U'll find urself swapping
between rotations regularly, even trading them in and out of eachother.
Just stay loose and watch your hate meters and you will tank like Arnold.
Pull:
(1) Heavy Swing or Tomahawk
> Flash when mobs are near
$ rake test:prepare
WARN: Unresolved specs during Gem::Specification.reset:
minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.