Skip to content

Instantly share code, notes, and snippets.

View littlelazer's full-sized avatar

Eryan Cobham littlelazer

  • Chicago, Illinois
View GitHub Profile
@littlelazer
littlelazer / gist:433dddfbf70f56e6ba7bb0c43d0f1ab6
Created February 22, 2020 17:12 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@littlelazer
littlelazer / immutable_complete.rb
Last active June 14, 2018 03:14
Immutable complete struct
$ Person = Struct.new(:first_name, :last_name) do
def initialize(*args)
raise ArgumentError, "Incorrect arguments" unless args[0].member?(:first_name) && args[0].member?(:last_name)
super(*args)
self.freeze
end
end
=> Person
$ eryan = Person.new(first_name: "Eryan")
@littlelazer
littlelazer / struct methods.rb
Last active June 21, 2018 18:49
Using enumerable/hash/array methods for structs
$ Employee = Struct.new(:first_name, :last_name, :email, keyword_init: true)
=> Employee(keyword_init: true)
$ employee = Employee.new(first_name: "Eryan", last_name: "Cobham", email: "eryan@devmynd.com")
=> #<struct Employee first_name="Eryan", last_name="Cobham", email="eryan@devmynd.com">
# output all properties of the struct, even uninitialized ones
$ employee.members
=> [:first_name, :last_name, :email]
@littlelazer
littlelazer / dig_struct.rb
Created June 14, 2018 03:01
Digging Structs
# Companies have Employees, and Employees have Addresses
$ Company = Struct.new(:name, :employees, keyword_init: true)
=> Company(keyword_init: true)
$ Employee = Struct.new(:first_name, :last_name, :address, keyword_init: true)
=> Employee(keyword_init: true)
$ Address = Struct.new(:street, :city, :state, :zip, keyword_init: true)
=> Address(keyword_init: true)
@littlelazer
littlelazer / accessing_members.rb
Created June 14, 2018 02:59
Different ways of accessing struct members
$ Client = Struct.new(:first_name, :last_name, keyword_init: true)
=> Client(keyword_init: true)
$ client_1 = Client.new(first_name: "Jamal", last_name: "Windsor")
=> #<struct Client first_name="Jamal", last_name="Windsor">
# using a getter
$ client_1.first_name
=> "Jamal"
@littlelazer
littlelazer / struct_kwargs.rb
Created June 14, 2018 02:55
Ruby Struct with kwargs
# Ruby 2.5
# Create a struct the new way
$ Coordinate = Struct.new(:latitude, :longitude, keyword_init: true)
=> Coordinate(keyword_init: true)
# keyword arguments, can define any property
$ chicago = Coordinate.new(longitude: -87.67897)
=> #<struct Coordinate latitude=nil, longitude=-87.67897>
@littlelazer
littlelazer / rails_new_help_output.md
Created March 8, 2018 20:35 — forked from eliotsykes/rails_new_help_output.md
"rails new" options explained

Run rails new --help to view all of the options you can pass to rails new:

$ bin/rails new --help
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /Users/eliot/.rbenv/versions/2.2.0/bin/ruby
@littlelazer
littlelazer / web-fonts-asset-pipeline.md
Created September 6, 2017 15:09 — forked from anotheruiguy/web-fonts-asset-pipeline.md
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

class ChildComponent extends React.Component {
render() {
const {hello} = this.props.greetings;
return <h1>{hello}</h1>;
}
}
const ChildContainer = Relay.createContainer(ChildComponent, {
initialVariables: {
name: 'A',
@littlelazer
littlelazer / capybara cheat sheet
Created June 13, 2017 17:45 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=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')