Skip to content

Instantly share code, notes, and snippets.

View nfilzi's full-sized avatar

Nicolas Filzi nfilzi

View GitHub Profile
@jaredcwhite
jaredcwhite / string_voodoo.rb
Last active June 23, 2021 18:14
JS in Ruby?!
### The Setup
Kernel.define_method(:"`") do |val|
val
end
def const(val)
val
end
@jmondo
jmondo / copy_ruby_class.py
Last active May 2, 2022 20:33
Copy ruby class sublime plugin
# Installation
# Go to Tools > Developer > New Plugin, copy this code, save it.
# Then open the key bindings file and add something like
# { "keys": ["super+k", "super+c"], "command": "copy_ruby_class_window" }
# Usage
# With any ruby file open call this command to copy the class name (including all the nested modules) to clipboard.
# Shoutout to https://github.com/astrauka/TestRSpec plugin for the parsing/re logic
import sublime
@mrmartineau
mrmartineau / stimulus.md
Last active July 18, 2024 07:43
Stimulus cheatsheet
@nfilzi
nfilzi / private_attr_methods_decorators.rb
Last active March 4, 2018 14:34
Module to get decorators for POROs to make `attr_*` private
module PrivateAttrMethodsDecorators
module Explicit
module ClassMethods
def private_attr_reader(*attributes)
attributes.each do |attr|
attr_reader attr
private attr
end
end

Ruby Association Certified Ruby Examination Gold Sample Questions

Q1. Assume that the following code must have the stated execution result.

__(1)__
x.each_line { |line| puts line }

[Execution Result]
apple
@mbajur
mbajur / .md
Created April 29, 2016 07:16
How to create small, unique tokens in Ruby

How to create small, unique tokens in Ruby

That is is basically a "fork" of blog article i'm constantly returning to. It seems that the blog is down:

My choice: Dave Bass’s rand().to_s() trick

Dave Bass proposed this which I picked up for my implementation (here for an 8-chars token):

When you modify a file in your repository, the change is initially unstaged. In order to commit it, you must stage it—that is, add it to the index—using git add. When you make a commit, the changes that are committed are those that have been added to the index.

git reset changes, at minimum, where your current branch is pointing. The difference between --mixed and --soft is whether or not your index is also modified. So, if we're on branch master with this series of commits:

- A - B - C (master)

HEADpoints to C and the index matches C.

--soft

@alexpchin
alexpchin / Ruby_Rails_Naming_Conventions.md
Created May 8, 2014 10:56
Ruby & Rails Naming Conventions

Alex's Rails Cheat Sheet

I think the most confusing thing that I have found about Ruby on Rails so far has been the transition from (trying to) write code myself to the use of the fabled "Rails Magic". So, to help my own understanding of a few core Ruby on Rails concepts, I have decided to write something on what I think is a CRITICAL topic... the idea of Convention over Configuration and why (in my mind) it is the most important thing that helps Rails become magic!

(This may be a topic that we cover in more detail in class but as I said, I'm writing this for my own understanding... I hope it helps someone else understand things too... Perhaps you can give me a hand when I'm crying next week!)

##Convention over configuration ###What does this "actually" mean...

@gitaarik
gitaarik / git_submodules.md
Last active July 26, 2024 13:44
Git Submodules basic explanation

Git Submodules basic explanation

Why submodules?

In Git you can add a submodule to a repository. This is basically a repository embedded in your main repository. This can be very useful. A couple of usecases of submodules:

  • Separate big codebases into multiple repositories.