Skip to content

Instantly share code, notes, and snippets.

View rakibulislam's full-sized avatar
🎯
Focusing

K M Rakibul Islam (Rakib) rakibulislam

🎯
Focusing
View GitHub Profile
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@rakibulislam
rakibulislam / cache.yml
Created November 24, 2020 18:21 — forked from ssaunier/cache.yml
Speed up the AWS Elastic Beanstalk of your Rails deployment with bundle/assets caching
# .ebextensions/cache.config
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/02a_set_cache.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
set -xe
def foo(x, y)
  method(__method__).parameters.map do |_, name|
    binding.local_variable_get(name)
  end
end

foo(1, 2)  # => 1, 2
class MyWorker
    def perform(params={})
      puts "params: #{params.inspect}"
      params = params.to_h.transform_keys(&:to_sym)
      puts "params after transform: #{params.inspect}"
      execute(**params)
    end

 def execute(name: "there", age: 20)

As outlined here, there are a couple of situations where you need to authenticate with GitHub by using an Acces Token:-

  1. If you have Two-Factor Authentication (2FA) enabled.
  2. You are accessing an organisations protected content using SAML Single-Sign On (SSO).

Create an Access Token

In your GitHub account, go to Settings / Developer settings / Personal access tokens and select Generate New Token. Make a note of the token somewhere safe since this is the only chance you get to see it.

Add the token to your local OSX Key Chain

# Here's an example of how you might set <tt>Time.zone</tt> on a per request basis and reset it when the request is done.
# <tt>current_user.time_zone</tt> just needs to return a string identifying the user's preferred time zone:
#
class ApplicationController < ActionController::Base
around_action :set_time_zone
def set_time_zone
if logged_in?
Time.use_zone(current_user.time_zone) { yield }
else
@rakibulislam
rakibulislam / user.rb
Created December 21, 2018 17:48 — forked from harlow/user.rb
Extract a validator in Rails. Zip code validation.
# app/models/user.rb
class User < ActiveRecord::Base
validates :zip_code, presence: true, zip_code: true
end
# DEBUG_RESOLVER=1 will show the activities of the resolver.
`DEBUG_RESOLVER=1 bundle update`
@rakibulislam
rakibulislam / memory-test.rb
Created December 3, 2018 02:51 — forked from mtrolle/memory-test.rb
High memory consumption, question asked on StackOverflow: https://stackoverflow.com/questions/53169751/ruby-memory-usage-gone-wild
require 'bundler/inline'
require 'json'
gemfile do
source 'https://rubygems.org'
gem 'rest-client'
gem 'nokogiri'
gem 'memory_profiler'
end
# semaphore:
old steps:
export RAILS_ENV=test
bundle install --deployment --path vendor/bundle
bundle exec rake db:create
bundle exec rake db:setup
bundle exec rake db:test:prepare
bundle exec rake spec