Skip to content

Instantly share code, notes, and snippets.

@clyfe
clyfe / simple_form.rb
Created August 22, 2013 08:20
Bootstrap3 compatible simple_form initializer
# http://stackoverflow.com/questions/14972253/simpleform-default-input-class
# https://github.com/plataformatec/simple_form/issues/316
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
@clyfe
clyfe / navigasmic.rb
Last active December 12, 2015 04:28
Navigasmic 0.5.6 monkeypatch initializer to allow block syntax and TB compatibility
Navigasmic.setup do |config|
config.highlighted_class = 'active'
config.with_group_class = 'dropdown-menu'
end
module Navigasmic
# lazy monkey patch, makes it work with twitter bootstrap
class HtmlNavigationBuilder
def item(label = '', options = {}, &proc)
@clyfe
clyfe / bf.ro
Last active October 13, 2015 03:47
black friday
# sudo apt-get install vlc vlc-plugin-pulse
require 'open-uri'
song = "Music/Creedence\\ Clearwater\\ Revival\\ -\\ Hey\\ Tonight.mp3"
loop do
begin
sleep 1
open("http://www.emag.ro/")
diff --git a/.gitignore b/.gitignore
index dfd12ee..bda50fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,4 @@ test/dummy/db/*.sqlite3
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
-/nbproject/private/
\ No newline at end of file
require "active_support"
module M1
def m; 1 end
end
module M2
def m; super + 1 end
end
@clyfe
clyfe / meal.rb
Created March 21, 2012 14:31
Simple search with Squeel DSL
class Meal < ActiveRecord::Base
belongs_to :chef
has_many :meal_translations, inverse_of: :meal, dependent: :destroy
scope :simple_search, ->(terms) {
joins{meal_translations}.
joins{chef.locations.outer}.
where{
{ meal_translations => sift(:simple_search, terms) } |
{ chef.locations.zip_code.eq_any => terms }
@clyfe
clyfe / behaviors.coffee
Created March 19, 2012 12:14
Reusable action components
$ ->
$('[data-remove-parent]').bind 'ajax:success', ->
el = $(this)
console.log el
console.log el.data('remove-parent')
console.log el.closest(el.data('remove-parent'))
el.closest(el.data('remove-parent')).fadeOut()
$('[data-live-input]').change ->
@clyfe
clyfe / overrides.css.scss
Created March 5, 2012 23:37
AS and TB play nice
/* use with AS 3.2 */
.active-scaffold-header div.actions {
top: 0;
}
.active-scaffold {
input[type="submit"], input[type="reset"], button {
@extend .btn;
@extend .btn-primary;
@clyfe
clyfe / ACL.rb
Created February 3, 2012 13:06
Short slides for a short talk at wurbe
#===================================================================
0. ACL - lists, individuals
- query DB conforming to ACL
@posts = Post.where( rules as per ACL ) # +joins
- authorize individuals already in memory
@post = Post.find(params[:id])
@clyfe
clyfe / trace.sh
Created January 30, 2012 10:27
AS Rails 3.2 migration error stack trace
[clyfe@sodium current]$ bundle exec rake RAILS_ENV=production db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Mysql2::Error: Table 'mydb.some_table' doesn't exist: SHOW FULL FIELDS FROM `some_table`
/SOME_PATH/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:233:in `query'