Skip to content

Instantly share code, notes, and snippets.

View tejasbubane's full-sized avatar
💭
WFH 🏡

Tejas Bubane tejasbubane

💭
WFH 🏡
View GitHub Profile
@tejasbubane
tejasbubane / activerecord_assignment_diff.rb
Last active March 7, 2018 07:15
Activerecord attribute assignment - direct vs self
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
@tejasbubane
tejasbubane / Gemfile
Last active July 13, 2017 13:03
warden JWT auth gem possible bug
source 'https://rubygems.org'
gem 'sinatra'
gem 'warden'
gem 'warden-jwt_auth'
@tejasbubane
tejasbubane / Newsletters
Created April 28, 2017 05:49
Some programming-related newsletters that I have subscribed to
* Ruby weekly: [http://rubyweekly.com/]()
* This week in Rails: [https://rails-weekly.ongoodbits.com/]()
@tejasbubane
tejasbubane / great_talks.md
Last active September 5, 2018 10:12
All time great Tech Talks that can be watched anytime anywhere. Watch'em over and over.
@tejasbubane
tejasbubane / example.exs
Created September 15, 2016 06:48
Exercism clock example implemented in elixir using tuples
defmodule Clock do
@doc """
Returns a string representation of a clock:
iex> Clock.new(8, 9) |> to_string
"08:09"
"""
@spec new(integer, integer) :: tuple
def new(hour, minute) do
rollover({hour, minute})
# Add `gem 'database_cleaner' to Gemfile (in test env)
# Add below code in spec_helper.rb or rails_helper.rb
require 'database_cleaner'
RSpec.configure do |config|
..........
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
@tejasbubane
tejasbubane / testing_basics.md
Last active June 18, 2016 11:08
Basics of Testing (Stubs, Mocks and Spies)

Some useful links for testing fundamentals:

  1. Test Pyramid - by Martin Fowler
  • Unit Testing (bottom) - Test all edge cases - very fast
  • Integration Testing (top) - Test happy paths - slower
  1. Test Doubles - by Martin Fowler

What makes unit tests fast is that they are being tested in isolation. To make them isolated we use Test Doubles.

@tejasbubane
tejasbubane / enums-activerecord.rb
Last active October 20, 2015 08:49
Enums in Rails
2.2.3 :001 > p = Post.first
Post Load (1.0ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT 1
=> #<Post id: 11, title: "Talk", content: "Giving a talk at Cybrilla", ..., category: "technology">
2.2.3 :002 > p.technology?
=> true
2.2.3 :003 > p.sports?
=> false
2.2.3 :004 > p.sports!
(0.3ms) BEGIN
SQL (0.5ms) UPDATE "posts" SET "updated_at" = $1, "category" = $2
@tejasbubane
tejasbubane / optimistic_locking.rb
Last active October 20, 2015 07:48
Optimistic Locking in Rails
2.2.3 :001 > p = Post.create(title: "My Talk", content: "Giving a talk at Cybrilla")
=> #<Post id: 3, title: "My Talk", content: "Giving a talk at Cybrilla", lock_version: 0, created_at: "2015-10-20 07:33:07", updated_at: "2015-10-20 07:33:07">
2.2.3 :002 > p1 = Post.first
=> #<Post id: 3, title: "My Talk", content: "Giving a talk at Cybrilla", lock_version: 0, created_at: "2015-10-20 07:33:07", updated_at: "2015-10-20 07:33:07">
2.2.3 :003 > p1.title = "ActiveRecord Talk"
=> "ActiveRecord Talk"
2.2.3 :004 > p1.save
=> true
2.2.3 :005 > p.content = "Tuesday Talk"
=> "Tuesday Talk"
@tejasbubane
tejasbubane / rsense-settings
Last active August 29, 2015 13:56
Activate RSense for awesome Ruby autocompletion in Emacs
Download and install (move to /opt)
$ wget http://cx4a.org/pub/rsense/rsense-0.3.zip
$ unzip rsence-0.3
$ cp -av rsense-0.3 /opt
Add to .bashrc or .zshrc
export RSENSE_HOME=/opt/rsense-0.3/
Re-open terminal and check the following:
$ echo $RSENSE_HOME