Skip to content

Instantly share code, notes, and snippets.

ApplicationController.allow_forgery_protection = false
app.post('/users/sign_in', {"users"=>{"email"=>"sam@example.com", "password"=>"password"}})
@JunilJacob
JunilJacob / clean_git_tags.sh
Created June 17, 2017 21:31 — forked from awilliams/clean_git_tags.sh
Delete multiple grepable tags from git
#!/bin/bash
for i in $( git tag -l | grep staging ); do
echo Tag: $i
#git tag -d $i
#git push origin :refs/tags/$i
done
@JunilJacob
JunilJacob / totp_2fa.rb
Created May 31, 2019 09:54 — forked from Nitrino/totp_2fa.rb
Rails mixin module for Two Factor Authentication (TOTP)
module OneTimePassword
# Concern containing logic and methods for OTP authentication.
# Is used Time-based One-time Password Algorithm(TOTP)
# https://tools.ietf.org/html/rfc6238
extend ActiveSupport::Concern
OTP_DIGITS = 6
OTP_NUMBER_OF_BACKUP_CODES = 10
OTP_BACKUP_CODE_LENGTH = 12
@JunilJacob
JunilJacob / base_controller.rb
Last active October 23, 2019 08:16
Request Rate Limiter
class Api::V3::BaseController < ActionController::Base
include Limiter
before_action -> { rate_limit(key: "api_#{doorkeeper_token.application_id}", rate: 60, interval: 60) }
private
def handle_rate_limit_exception
log_exception RateLimitError.new("Rate limit reached for #{doorkeeper_token.application.name}")
render json: { error: { type: "rate_limit_exceeded", message: "Rate limit exceeded." } }, status: 429
@JunilJacob
JunilJacob / CryptoKeyGenerator.java
Created September 30, 2021 08:30
Encrypted Credentials Java Selenium
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class CryptoKeyGenerator {
public static void main(String[] args) throws NoSuchAlgorithmException {
SecretKey key = KeyGenerator.getInstance("AES").generateKey();
String encodedKey = Base64
@JunilJacob
JunilJacob / CommonUtils.java
Created September 30, 2021 08:35
Upload Files in Selenium for different OS
package utility;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import org.apache.commons.lang3.SystemUtils;
import org.openqa.selenium.WebElement;
public class CommonUtils {
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
@JunilJacob
JunilJacob / with_retries.rb
Created June 27, 2022 18:45 — forked from cainlevy/with_retries.rb
with_retries{} helper to easily catch and retry exceptions in Ruby
module Retriable
# This will catch any exception and retry twice (three tries total):
# with_retries { ... }
#
# This will catch any exception and retry four times (five tries total):
# with_retries(:limit => 5) { ... }
#
# This will catch a specific exception and retry once (two tries total):
# with_retries(Some::Error, :limit => 2) { ... }
#

##Working configuration to accomplish 0-downtime deploy with unicorn 5.x and systemd on centos 7

The scope is to accomplish a 0-downtime reload of a unicorn service managed by Systemd on a Centos 7 distro.

The examples and assumptions that i found on the bogomips's unicorn repo seems not working for centos 7.

Below a working configuration tested on Centos 7 and unicorn 5.1

Any advice/remark will be appreciated

@JunilJacob
JunilJacob / bash_strict_mode.md
Created January 23, 2024 07:11 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation