Skip to content

Instantly share code, notes, and snippets.

@kenakingkong
kenakingkong / actiontext.scss
Last active November 10, 2024 21:22
Trix Editor - Stimulus Controller and CSS styles
/* https://medium.com/@makenakong/how-to-add-and-customize-the-trix-editor-for-your-ruby-on-rails-application-c0a5d3082254 */
.trix-button--icon-strike,
.trix-button--icon-link,
.trix-button-group--block-tools,
.trix-button-group--file-tools,
.trix-button-group--history-tools {
display: none;
}
@mrmartineau
mrmartineau / stimulus.md
Last active September 24, 2024 21:07
Stimulus cheatsheet
@mankind
mankind / rails-jsonb-queries
Last active November 12, 2024 13:02
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@kevinelliott
kevinelliott / osx-10.11-setup.md
Last active September 5, 2024 01:54
Mac OS X 10.11 El Capitan Setup

Mac OS X 10.11 El Capitan

Custom recipe to get OS X 10.11 El Capitan running from scratch, setup applications and developer environment. This is very similar (and currently mostly the same) as my 10.10 Yosemite setup recipe (as found on this gist https://gist.github.com/kevinelliott/0726211d17020a6abc1f). Note that I expect this to change significantly as I install El Capitan several times.

I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.

@daniely
daniely / rolify_with_fixtures.md
Created May 13, 2015 19:00
rolify with fixtures

I'm using rails 4.2 and had a tough time with rolify and rails fixtures. After some mucking I finally got it working. Posting here incase someone else needs to do something similar.

  1. Create a UsersRole model in models/users_role.rb
# pretty much exclusively created for our fixtures to work
class UsersRole < ActiveRecord::Base
  belongs_to :user
  belongs_to :role
end
@samselikoff
samselikoff / future-proof.md
Last active August 15, 2024 15:17
Future-proofing your Ember 1.x code

This post is also on my blog, since Gist doesn't support @ notifications.


Components are taking center stage in Ember 2.0. Here are some things you can do today to make the transition as smooth as possible:

  • Use Ember CLI
  • In general, replace views + controllers with components
  • Only use controllers at the top-level for receiving data from the route, and use Ember.Controller instead of Ember.ArrayController or Ember.ObjectController
  • Fetch data in your route, and set it as normal properties on your top-level controller. Export an Ember.Controller, otherwise a proxy will be generated. You can use Ember.RSVP.hash to simulate setting normal props on your controller.
@rosenfeld
rosenfeld / application_controller.rb
Created July 18, 2014 11:47
Supporting automatic return from render/redirect/head in Rails
# Please don't comment in this gist since I'm not notified by any comments here:
# https://github.com/isaacs/github/issues/21
# This is the discussion to comment on: http://blog.arkency.com/2014/07/4-ways-to-early-return-from-a-rails-controller/
class ApplicationController < ActionController::Base
# ...
around_action :catch_halt
def render(*args)
#=Navigating=
visit('/projects')
visit(post_comments_path(post))
#=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click_on('Button Value')
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end