Skip to content

Instantly share code, notes, and snippets.

View 8parth's full-sized avatar

Parth Modi 8parth

View GitHub Profile
@HSPDev
HSPDev / AllowSSHFromIP.php
Created July 2, 2018 22:56
Complementary code and IAM policy for "You don't need that Bastion host"
<?php
// For laravel 5 based systems
// /path/to/project/app/Console/Commands/AllowSSHFromIP.php
namespace App\Console\Commands;
use Aws\Ec2\Ec2Client;
use Carbon\Carbon;
use Illuminate\Console\Command;
# config/initializers/activestorage.rb
Rails.application.config.to_prepare do
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
ActiveStorage::Attached::Macros.module_eval do
def has_one_attached(name, dependent: :purge_later, acl: :private)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"}, acl: "#{acl}")
end
@osulyanov
osulyanov / config.yml
Last active November 30, 2022 23:58
Circle CI workflows config to test and deploy Ruby on Rails application with PostgreSQL database. Test with Rspec, precompile assets then deploy with Capistrano.
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/ruby:2.4.1-node-browsers
environment:
@felicianotech
felicianotech / gist:56ad8f63156e233e6a16df50fe6d4791
Created August 22, 2017 23:02
Using AWS ECR with CircleCI 2.0 (docker executor)
version: 2
jobs:
build:
docker:
- image: circleci/openjdk:8-jdk
steps:
- checkout
- setup_remote_docker
- run:
name: install aws
@Disha-Shah
Disha-Shah / override_activerecord_validation_errors.yml
Created July 26, 2017 06:41
Rails - Override Activerecord validation errors
activerecord:
attributes:
address:
phone: "Phone"
name: "Street Name"
line1: "Address line 1"
city: "Address line 2"
state: "State"
country: "Country"
pincode: "Pincode"
@clarkdave
clarkdave / ecs-interactive-console.sh
Last active January 31, 2023 19:26
ecs-interactive-console
#!/bin/bash -e
##
# Use this annotated script a base for launching an interactive console task on Amazon ECS
#
# more info: https://engineering.loyaltylion.com/running-an-interactive-console-on-amazon-ecs-c692f321b14d
#
# Requirements:
# - `jq` must be installed on both the client and server
##
@libitte
libitte / gist:cbde168d26bc5faf9bf9fef648091b42
Last active November 11, 2022 19:30
FIX warning: ignoring broken ref refs/remotes/origin/HEAD

warning: ignoring broken ref refs/remotes/origin/HEAD


➜   ✗ g symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/develop
➜   ✗ g fetch --prune
➜   ✗ g gc

@mankind
mankind / rails-jsonb-queries
Last active April 17, 2024 12:14
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@Disha-Shah
Disha-Shah / staging_production_env_git_heroku.md
Created January 3, 2017 06:53
Create 2 environments - Staging and Production from same App (Heroku and Git)

NOTICE: When I say "appname" it means enter your own! It's not a command or name native to git or Heroku. By default, your one and only remote is called "heroku". This is why you do things like $ git push heroku master, you're pushing to the master branch of heroku. What we want is two remotes: one staging, one production. You can view your remotes by typing...

$ heroku apps:create staging-appname
$ git remote -v 
   // this should return:
   // heroku	git@heroku.com:appname.git (fetch)
   // heroku	git@heroku.com:appname.git (push)

So, lets rename that default heroku git remote to a staging, production one.

@chansuke
chansuke / Capfile
Last active May 15, 2022 16:53
Capistrano deploy setting(via bastion)
# AWS SDK
require 'aws-sdk'
Aws::EC2::Resource
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
require 'capistrano/safe_deploy_to'