Skip to content

Instantly share code, notes, and snippets.

View reddyonrails's full-sized avatar

Jagan Reddy reddyonrails

View GitHub Profile
@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();
@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