Skip to content

Instantly share code, notes, and snippets.

View reddyonrails's full-sized avatar

Jagan Reddy reddyonrails

View GitHub Profile
@reddyonrails
reddyonrails / dynamic_class.rb
Created October 23, 2015 19:33
Creating dynamic class with name space from string in Ruby
module Util
# Create Job class from ENV string
def self.create_job_class(name, queue_var)
klass = Class.new(ActiveJob::Base) do
queue_as ENV.fetch(queue_var, 'default')
end
create_dynamic_class(name, klass)
end
@reddyonrails
reddyonrails / formik-debug.js
Last active May 26, 2020 23:37
formik-debug.js
{debug && (
<>
<pre style={{ textAlign: "left" }}>
<strong>Values</strong>
<br />
{JSON.stringify(values, null, 2)}
</pre>
<pre style={{ textAlign: "left" }}>
<strong>Values</strong>
<br />
// Store Redux
state = {
cars: {
carsById: {
1: { id: 1, name "Toyota" },
2: { id: 2, name "Lexus" },
3: { id: 3, name "Honda" }
}
}
};
// Store Redux
state = {
cars: {
carsById: {
1: { id: 1, name "Toyota" },
2: { id: 2, name "Lexus" },
3: { id: 3, name "Honda" }
}
}
};
@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:
@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 / 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 / FactoryBot
Created September 10, 2018 20:20
FactoryBot for development
`require 'factory_bot'`
`FactoryBot.find_definitions`
@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;
}
var Bar1 = base => class extends base {
componentWillMount(){
super.componentWillMount();
console.log('Bar1');
}
};
var Bar2 = base => class extends base {
componentWillMount(){
super.componentWillMount();