Skip to content

Instantly share code, notes, and snippets.

View gist:3620999ff97a19cbd45a
GET /api/me/attendables
{
attendables: [
# Members Party
{
event_type: "members_party",
attendable_guid: "abcde",
attendable_type: "Party",
initiat: null,
View useful eng tools.md

ngrok - for forwarding a local/port to the internet

@zimkies
zimkies / users_with_overlapping_requests.rb
Created Mar 17, 2015
Finding the number of users who have had 2 confirmed grouper requests at any one time
View users_with_overlapping_requests.rb
require 'date'
class Range
def intersection(other)
return nil if (self.max < other.begin or other.max < self.begin)
[self.begin, other.begin].max..[self.max, other.max].min
end
alias_method :&, :intersection
end
@zimkies
zimkies / Sublime patterns.md
Created Sep 25, 2014
General patterns I find useful in Sublime
View Sublime patterns.md

Move file: Cmd Sh p | f m Rename file: Cmd Sh p | f r

Multi-select cursor skip current selection: Cmd k

@zimkies
zimkies / leader_been_to_venue.rb
Created Sep 19, 2014
The problem with separating out models into purely their own concerns
View leader_been_to_venue.rb
# FML You are joking right?
# THere has to be something wrong with this model.
def user_has_been_to_venue?(user, venue)
Reservation.joins("LEFT JOIN venues_tables ON venues_tables.id = reservations.table_id LEFT JOIN venues ON venues_tables.venue_id = venues.id LEFT JOIN groupers ON groupers.id = reservations.grouper_id LEFT JOIN crews ON crews.grouper_id = groupers.id LEFT JOIN users ON users.id = crews.leader_id")
.where("crews.leader_id = ?", user.id)
.where("venues.id = ?", venue.id).exists?
end
@zimkies
zimkies / pool creation.rb
Last active Aug 29, 2015
Code for creating pool objects for the future
View pool creation.rb
class PoolsCreator
def create_all
Week.where("starting_on > ?", 1.week.ago).each do |week|
create_for_week(week)
end
end
def create_for_week(week)
City.active.each do |city|
View resque
Hi there,
There's no downside to opening connections on initialization or after forking, even if you don't use the connections often. Aside from reducing the chance for connection errors during the request loop, you'll also speed up your request loop by not spending time establishing new connections. I definitely recommend making this change if you can.
For Resque, there's unfortunately no way around the fact that every job is run inside a forked process and can't inherit or share any connections. You'll have to open a new Redis connection for every Resque job that uses Redis. The best way to do this inside the "after_fork" Resque hook. If you use ActiveRecord, it's likely that you're already establishing a new connection inside this hook. Here's what our after_fork hook looks like, in our config/initializers/resque.rb file:
```ruby
Resque.after_fork do
tries = 0
begin
$redis.client.reconnect
ActiveRecord::Base.establish_connection
rescue
View I18n_learnings.md

This is a summary of all of our key learnings from the I18n sprint. I've also added this to our best practices page

Presenters vs Decorators

Decorators

Decorators are classes we use to add presentation logic to specific models. They should be instantiated with a single model. An example is the Member Decorator The MemberDecorator adds presentation logic to the Member model, which shouldn't know how to render your friends_gender, for instance.

Presenters

View gist:8806276
try_guest_pass_html: |
Or try Grouper with a
<a href='%{next_path}' class='%{link_class}'>Guest Pass</a>
<br />
They run %{price} per person and can only be used on your first Grouper.
@zimkies
zimkies / bootstrap_hide_show.coffee
Last active Mar 23, 2016
MonkeyPatch for Jquery hide() and show() to work with Bootstrap 3
View bootstrap_hide_show.coffee
# MonkeyPatch for Jquery hide() and show() to work with Bootstrap 3
#
# Bootstrap 3 defines hidden and hide with the !important marker which
# prevents .show() and .hide() from working on elements that have been
# hidden using these classes.
# This patch modifies the hide and show to simply add and remove these
(($) ->
show = $.fn.show
$.fn.show = ->
@removeClass("hidden hide")