Skip to content

Instantly share code, notes, and snippets.

View dinobi's full-sized avatar
🏠
working remotely

DnoB dinobi

🏠
working remotely
  • @jane.app
  • British Columbia, Canada
View GitHub Profile
@dinobi
dinobi / rails_new_help_output.md
Created January 19, 2021 14:30 — 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
@dinobi
dinobi / cap.rb
Created October 30, 2020 14:12 — forked from trivektor/cap.rb
Kill resque workers using rake task, let god handle the restart
after "deploy:restart", "resque:stop_workers"
namespace :resque do
task :stop_workers, :except => { :no_release => true } do
run "cd #{current_path} && rake RAILS_ENV=#{rails_env} resque:stop_workers"
end
end
@dinobi
dinobi / form_object.rb
Created January 26, 2019 13:05
Using form extraction pattern for reducing bloated active record models
# Using Form Object Extraction Pattern
class UserNoteForm
include ActiveModel::Model
def persisted?
false
end
attr_accessor :user_note
@dinobi
dinobi / service_object.rb
Created January 26, 2019 12:00
Using service object extraction pattern to reduce bloated active record models
# Using Service Object Extraction Pattern
class Product < ActiveRecord::Base
end
class UserNoteService
require ostruct
def initialize(object)
@object = object
end
@dinobi
dinobi / value_object.rb
Created January 26, 2019 11:02
Using value object extraction pattern to reduce bloated active record models
# Using Value Object Extraction Pattern
class Product < ActiveRecord::Base
def user_note
UserNote.new(user_note)
end
def user_note=(user_note)
self.user_note = user_note.note
end
@dinobi
dinobi / delegation_pattern.rb
Last active January 26, 2019 10:40
Using delegation pattern to refactor fat ActiveRecord models
# Using Delegation Pattern
class Product < ActiveRecord::Base
# instead of defining a notes method inside Product class
# where we can perform some arbitrary logic on user notes,
# we can simply delegate the note method to the UserNote class
#
# USAGE: product.user_note
delegate :note, to: :user_note, prefix: :user
end
@dinobi
dinobi / rails http status codes
Created May 1, 2018 14:01 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
#!/usr/bin/env bash
# Welcome to my sample command line session
pwd #show the current directory
ls #list files in the current directory
mkdir sample-dir1 #create a new directory
cd sample-dir1 #navigate to a directory
cd .. #switch to the directory above this
mkdir sample-dir2 #create another directory
cd sample-dir2
touch sample_script.rb #create ruby script file
@dinobi
dinobi / goal_challenge_activity_main.xml
Last active May 18, 2017 23:58
XML code for the Goal Challenge Android App
<!-- I decided not to use the styles resources to hold related view states, so that all values can be seen at a glance -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context="com.example.android.goalchallenge.MainActivity">
@dinobi
dinobi / GoalChallenge_MainActivitity.java
Last active May 13, 2017 13:03
Android app that randomly awards score to paired opponents based on score point and comments out the winner after 20 plays
package com.example.android.goalchallenge;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
//Variables to hold global data that will be accessed by methods