Skip to content

Instantly share code, notes, and snippets.

View emzeq's full-sized avatar

Aurelio Agundez emzeq

  • Kaggle
  • Corona, CA
View GitHub Profile
@emzeq
emzeq / machine.js
Created April 10, 2020 02:45
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@emzeq
emzeq / super_word_search.py
Created July 25, 2012 22:32
Super Word Search Solution
from collections import defaultdict
class SuperWordSearch:
"""
Solves the Super Word Search variation of the word search problem.
"""
# All 8 directions (left to right, top to bottom, etc.)
DIRECTIONS = ((0,1),(1,0),(-1,0),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1))
@emzeq
emzeq / q4.rb
Created July 9, 2012 22:54
Consistent Shard
# Append shard ranges as new shard groups are brought online
# Format: [Cutoff User ID, Min Shard, Max Shard]
USER_ID_SHARD_MAPPING = [
[0, 1, 10],
[30000, 11, 20],
[500000, 21, 50],
]
# Consistent shard that falls within a shard range by the user’s ID
def consistent_shard(user)
@emzeq
emzeq / orders.rb
Created August 10, 2011 16:32
rails3-jquery-autocomplete in ActiveAdmin
form do |f|
f.form_buffers.last << f.autocompleted_input(:product_name, url: autocomplete_product_name_orders_path, label: 'Product')
end
@emzeq
emzeq / gist:994302
Created May 26, 2011 23:00
User Context in Resource Registration
ActiveAdmin.register Product do
authorized_actions = [:index, :show, :new, :create]
authorized_actions << :destroy if current_admin_user.super_admin?
actions authorized_actions
end
@emzeq
emzeq / gist:985758
Created May 22, 2011 19:03
Active Admin 'all' Scope Perf Workaround
scope :all, default: true do |products|
products.where('1 = 1')
end