Skip to content

Instantly share code, notes, and snippets.

@sankalpk
sankalpk / gist:2d7d49ed073217402db8e94af1fa481a
Created May 13, 2019 18:06
Create Redshift Read Only User
CREATE GROUP ro_group;
CREATE USER <user_name> WITH password '<password>';
ALTER GROUP ro_group ADD USER <user_name>;
GRANT USAGE ON SCHEMA "public" TO GROUP ro_group;
@sankalpk
sankalpk / gist:f677c2617f7031ebed46dae8353b8cef
Created May 22, 2019 17:46
Run prettier fix on all files
prettier --write 'src/**/*.scss'
prettier --write 'src/**/*.css'
prettier --write 'src/**/*.js'
prettier --write 'src/**/*.jsx'
prettier --write 'src/**/*.html'
prettier --write 'public/**/*.html'
@sankalpk
sankalpk / readme.md
Last active May 25, 2019 05:08
Flask command not found with asdf

From the readme: https://github.com/danhper/asdf-python

If you use pip to install a module like ipython or flask that has a binaries. You will need to run asdf reshim python for the binary to be in your path.

asdf reshim python
@sankalpk
sankalpk / commands.md
Last active August 21, 2019 20:50
Populate a Rails app w/ Elasticsearch

Clear and populate the database with fresh data:

rake db:populate

Clear the database:

rake db:clean
@sankalpk
sankalpk / create_user_mutation_spec.rb
Last active May 5, 2020 14:48
Create User Mutation Spec Example
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Mutations::CreateUser, 'create user mutation' do
before(:all) do
@basic_mutation = <<-GRAPHQL
mutation CreateUser($firstName: String!, $lastName: String!, $ssn: String, $dob: ISO8601Date!) {
createUser(firstName: $firstName, lastName: $lastName, ssn: $ssn, dob: $dob) {
user {
@sankalpk
sankalpk / config.js
Last active June 3, 2020 04:41
Update files for debugging
import runtimeEnv from '@mars/heroku-js-runtime-env'
const env = runtimeEnv()
const dotenv = require('dotenv')
dotenv.config()
export const {
REACT_APP_GRAPHQL_API_URL,
REACT_APP_BUGSNAG_KEY,
import React, { Component } from 'react'
import mobiscroll from '@mobiscroll/react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import TextInput from 'components/TextInput'
mobiscroll.settings = {
theme: 'material',
themeVariant: 'light',
class ArrayValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
array_elements_are_unique(record, attribute, value)
array_elements_are_subset_of_valid_list(record, attribute, value, options[:with])
field_is_present(record, attribute, value)
end
def array_elements_are_unique(record, attribute, value)
if value.present? && (value.uniq.size < value.size)
record.errors.add(attribute, 'are duplicated')
@sankalpk
sankalpk / log_constants.rb
Created July 21, 2020 01:17
Log Constants
#config/initializers/log_constants
module LogConstantLoading
@@log_depth = 0
def load_missing_constant(from_mod, const_name)
log_loading("load_missing_constant(#{from_mod}, #{const_name})") do
super
end
end
@sankalpk
sankalpk / debugReactHook.js
Last active August 28, 2020 23:16
Add react-hook-form debug component
// Import component and react-hook-form
import { DevTool } from "@hookform/devtools";
import { useForm } from "react-hook-form";
// Grab the control object form from the useForm hook
const { control, register, handleSubmit, errors } = useForm()
// Add component to wherever on the page
<DevTool control={control} />