Skip to content

Instantly share code, notes, and snippets.

@leastbad
leastbad / README.md
Created April 16, 2020 08:08
Choices.js Stimulus wrapper preview

Choices.js Stimulus wrapper

https://joshuajohnson.co.uk/Choices/

Soon, this will be published as an NPM package, but there's an absence of documentation right now. It supports almost all functions from the original library; soon it will support 100% of them.

This wrapper adds Ajax pre-fetch search. Happens if controller has a data-search-path attribute.

Stimulus controller targets use new v2 syntax. Controller attaches a reference to itself on the element so that you can access the internal state from external scripts.

@JuanVqz
JuanVqz / simple_form_bulma.rb
Last active September 12, 2024 19:31
Support for simple form with bulma css, copy and paste on config/initializers/simple_form_bulma.rb
# frozen_string_literal: true
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Default class for buttons
config.button_class = "button"
# Define the default class of the input wrapper of the boolean input.
config.boolean_label_class = "checkbox"
@rohitrawat
rohitrawat / sources.list
Created June 12, 2017 18:17
Ubuntu 16.04 Xenial default /etc/apt/sources.list
#deb cdrom:[Ubuntu 16.04.2 LTS _Xenial Xerus_ - Release amd64 (20170215.2)]/ xenial main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
@arjunvenkat
arjunvenkat / gist:1115bc41bf395a162084
Last active January 12, 2024 05:04
Seeding a Rails database with a CSV file

How to seed a Rails database with a CSV file

1. Setup

First, Create a folder inside of lib called seeds

Put your CSV file example.csv into the lib/seeds folder. In the example below, the file is called real_estate_transactions.csv

Make sure you've created a resource with the appropriate columns to match your seed data. The names don't have to match up.

@iangreenleaf
iangreenleaf / gist:b206d09c587e8fc6399e
Last active September 5, 2025 19:33
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@witooh
witooh / graphicsmagick.sh
Created February 1, 2015 17:42
Install Graphicsmagick
sudo apt-get install python-software-properties
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:rwky/graphicsmagick
sudo apt-get update
sudo apt-get install graphicsmagick
@carter2422
carter2422 / alternate-unhide
Last active August 29, 2015 14:10
Unhide objects and keep them unselected.
bl_info = {
"name": "Alternate Object Hiding",
"author": "Jonathan Williamson",
"version": (1, 0),
"blender": (2, 65, 0),
"location": "View3D",
"description": "Unhides objects while keeping them deselected",
"warning": "",
"wiki_url": "",
"category": "Object"}
@jackrg
jackrg / active_record.rb
Created May 16, 2014 18:14
Add bulk import functionality to Rails Active Record (add this file to config/initializers, call <model>.import!(array-of-record-hashes))
class ActiveRecord::Base
def self.import!(record_list)
raise ArgumentError "record_list not an Array of Hashes" unless record_list.is_a?(Array) && record_list.all? {|rec| rec.is_a? Hash }
return record_list if record_list.empty?
(1..record_list.count).step(1000).each do |start|
key_list, value_list = convert_record_list(record_list[start-1..start+999])
sql = "INSERT INTO #{self.table_name} (#{key_list.join(", ")}) VALUES #{value_list.map {|rec| "(#{rec.join(", ")})" }.join(" ,")}"
self.connection.insert_sql(sql)
=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('Button Value')
@jdickey
jdickey / SOLVED Specifying namespaces in a Rails routing spec.md
Last active August 29, 2015 13:57
SOLVED specifying namespaces in a Rails routing spec.

FINALLY! For the three of you who have been following this epic saga through Gists 9907240 and 9908206, we have finally found the elusive green bar; a mystery wrapped in an enigma disguised as a riddle.

There were two key changes that made this work:

  1. The describe group containing the routing spec must have the annotation :type => :routing; and
  2. The route I was actually trying to get was /blog/blog.

The fact that get 'index' returns success in the third spec in the file is the most flaming of red herrings I've seen in a long, long time.

Green-bar-inducing code and spec files follow. The routing is unchanged from that quoted in the first Gist.