Skip to content

Instantly share code, notes, and snippets.

View reddyonrails's full-sized avatar

Jagan Reddy reddyonrails

View GitHub Profile
@reddyonrails
reddyonrails / rspec_custom_macro.rb
Last active May 12, 2017 05:12
Rspec custom macro like let or let! => pass multiple keys to define array of lets under example group
module RSpec
module Core
module MemoizedHelpers
module ClassMethods
# Usage: ways of defining config getters
# Before:
# let!(:user_1) { DataSource.get(:user_1) }
# let!(:user_2) { DataSource.get(:user_2) }
# After:
redis-cli --raw keys 'namespace:*'|xargs -L1 redis-cli del
Verifying my Blockstack ID is secured with the address 15AxSKrwo7Cwnzqa9Zq2T6iB2GpYKVAYDw https://explorer.blockstack.org/address/15AxSKrwo7Cwnzqa9Zq2T6iB2GpYKVAYDw
@reddyonrails
reddyonrails / self_chain.rb
Created April 15, 2018 18:57
use instance methods with self for method chaining
class Module
def with_chain(&block)
m = Module.new
m.instance_eval(&block)
m.methods(false).each do |name|
define_method name do
m.method(name).call
self
end
var Bar1 = base => class extends base {
componentWillMount(){
super.componentWillMount();
console.log('Bar1');
}
};
var Bar2 = base => class extends base {
componentWillMount(){
super.componentWillMount();
@reddyonrails
reddyonrails / async_generator.js
Created July 20, 2018 23:29
async_generator.js
async function *getRecords() {
const initialResponse = await getRecords();
yield* initialResponse.data;
let nextPage = initialResponse.pagination_token;
while(nextPage) {
const response = await getRecords(nextPage);
yield* response.data;
nextPage = response.pagination_token;
}
@reddyonrails
reddyonrails / FactoryBot
Created September 10, 2018 20:20
FactoryBot for development
`require 'factory_bot'`
`FactoryBot.find_definitions`
@reddyonrails
reddyonrails / git
Last active August 20, 2019 16:58
Delete merged branches (locally)
$ git branch --merged master | grep -v "\* master" | xargs -n 1 git branch -d && git remote prune origin
@reddyonrails
reddyonrails / nested-redis.rb
Created November 6, 2019 17:59 — forked from Loupi/nested-redis.rb
Redis Nested Comments in Ruby
require 'redis'
require 'json'
class CommentsRepository
def initialize
@redis = Redis.new
end
def save(itemId, comment, parentId = nil)
@reddyonrails
reddyonrails / rspec_model_testing_template.rb
Created November 8, 2019 23:04 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems: