Skip to content

Instantly share code, notes, and snippets.

View aritode's full-sized avatar
🎼

Arian Deli aritode

🎼
View GitHub Profile

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@aritode
aritode / interpreter_to_compiler.md
Created October 16, 2019 05:51 — forked from mrnugget/interpreter_to_compiler.md
So you're finished with "Writing An Interpreter In Go" and want to read more?

This is what I once wrote to a reader:

  • Nand2Tetris book - http://www.nand2tetris.org/
  • The paper "An Incremental Approach to Compiler Construction", by Abdulaziz Ghuloum. You can find a hosted PDF version of the paper and an implementation of its contents here: https://github.com/namin/inc\
  • Jack Crenshaw's classic "LET'S BUILD A COMPILER" from 1988. Even though it's kinda dated (he's using Turbo Pascal), it's one of the great "let's roll our sleeves up and write some code" texts. Here is the PDF version: http://compilers.iecc.com/crenshaw/tutorfinal.pdf
  • Then there are also the 4th and 5th chapters of Structure an Interpretation of Computer Programs (SICP), in which you'll build an interpreter and a kinda bytecode-compiler for a virtual register machine. It's a pretty abstract and seemingly alien affair (using a Lisp dialect to build a virtual register machine for a bytecode defined in Lisp, produced by a Lisp compiler, etc.), but it teaches the concepts behind the whole compiler and VM thing.
@aritode
aritode / ticket.rb
Created May 21, 2019 19:46 — forked from dhh/ticket.rb
class Ticket < ActiveRecord::Base
belongs_to :grouper
belongs_to :user
validate :user_cant_be_blacklisted, on: :confirmation
validate :user_cant_double_book, on: :confirmation
validate :grouper_cant_be_full, on: :confirmation
validate :grouper_cant_have_occurred, on: :confirmation
@aritode
aritode / rendering_partials.md
Created May 2, 2019 02:47 — forked from olivierlacan/rendering_partials.md
How to use shorthand syntax for rendering partials in Rails

Inside of Rails views, you can call partial views (any view file named with an underscore as the first character) like this:

render partial: "partial_name"

You can also pass local variables, which is fantastic to ensure that your views & partials don't try to access data you didn't specifically hand to them from the controller.

@tylerhunt showed me this week that it was possible to avoid using instance variables (which are copied from the Rails controller to the corresponding Rails views) altogether by passing local variables to the view.

@aritode
aritode / regenerate_credentials.md
Created March 29, 2019 13:36 — forked from db0sch/regenerate_credentials.md
How to regenerate the master key for Rails 5.2 credentials

If your master.key has been compromised, you might want to regenerate it.

No key regeneration feature at the moment. We have to do it manually.

  1. Copy content of original credentials rails credentials:show somewhere temporarily.
  2. Remove config/master.key and config/credentials.yml.enc
  3. Run EDITOR=vim rails credentials:edit in the terminal: This command will create a new master.key and credentials.yml.enc if they do not exist.
  4. Paste the original credentials you copied (step 1) in the new credentials file (and save + quit vim)
  5. Add and Commit the file config/credentials.yml.enc
@aritode
aritode / README.md
Created March 4, 2019 03:44 — forked from shiftyp/README.md
OOP Quiz App

OOP and MVC

What and Why

One of the big leaps you'll have to make as a JavaScript developer is wrapping your head around Object Oriented Programming (OOP). This is tough, and that's ok because it's tough for everyone at first. When you start out with JavaScript you're taught to use functions as your primary way of organizing your code. This is fine, but you'll probably find that organizing your code around objects makes larger projects easier to accomplish and improve / maintain.

The cool thing is that what OOP amounts to is an organizational strategy. I have a set of related tasks, how do I go about starting the project and organizing my code? These tasks have some variables and functions that are used to accomplish them, so you create them and write the logic for them to interact. While you can write those out as detached functions and variables, making those variables and functions into properties and methods of an object can make the division between those tasks easier to see and maintain.

Maint

@aritode
aritode / on-css.md
Created November 13, 2018 15:47 — forked from jamesarosen/on-css.md
On CSS

I don't have a Grand Vision for (S)CSS, but I do have some ideas.

Cohesion & Coupling

In JavaScript (and any other "programming language"), we value cohesion and eschew coupling. To value cohesion is to say that all of the foo-related things are in the Foo component or the app/pods/foo pod or the lib/foo addon. Like things are together. To eschew coupling is to say that two unrelated things should not need to know about one another. Unlike things don't rely on one another. Further reading on Cohesion & Coupling:

@aritode
aritode / towards_a_better_rails_navigation_plugin.md
Created November 13, 2018 15:37 — forked from jamesarosen/towards_a_better_rails_navigation_plugin.md
README for a proposed Rails navigation helper

Tired of building custom navigation code for each site?

Have you seen Ryan Heath's Navigation Helper? It's very usable, but it only does one nav-bar. I often have sites where there are many, e.g.

+-----------------------------------------------------------+
| MyApp                           | Home | Sign Out | FAQ | | # "site" nav bar
|===========================================================|
| | *Projects* | Friends |                                  | # "area" nav bar
|===========================================================|

| | Project Overview | Budget | History | | # "tabs" nav bar

@aritode
aritode / bm_erb_render.rb
Created November 7, 2018 19:02 — forked from k0kubun/bm_erb_render.rb
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores
# based on ruby/benchmark/bm_erb_render.rb
require 'benchmark/ips'
require 'erb'
require 'erubi'
require 'erubis'
data = DATA.read
mod = Module.new
mod.instance_eval("def self.erb(title, content); #{ERB.new(data).src}; end", "(ERB)")
@aritode
aritode / github-wiki-how-to.md
Created October 21, 2018 12:46 — forked from subfuzion/github-wiki-how-to.md
GitHub Wiki How-To

How do I clone a GitHub wiki?

Any GitHub wiki can be cloned by appending wiki.git to the repo url, so the clone url for the repo https://myorg/myrepo/ is: [email protected]/myorg/myrepo.wiki.git (for ssh) or https://github.com/my/myrepo.wiki.git (for https).

You make edits, and commit and push your changes, like any normal repo.

How do I add images to a wiki page?

You need to clone the wiki repo and edit it on your system.