Skip to content

Instantly share code, notes, and snippets.

View kitwalker12's full-sized avatar

Kunwar Aditya Raghuwanshi kitwalker12

View GitHub Profile
@kitwalker12
kitwalker12 / config.yml
Created March 7, 2018 22:28
Upgrade Circleci to 2.0 Config
version: 2
jobs:
build:
parallelism: 3
working_directory: ~/foo/bar
docker:
- image: circleci/ruby:2.3-node-browsers
- image: circleci/postgres:9.4
- image: circleci/redis:3.2
- image: circleci/rabbitmq:3.6.6
@kitwalker12
kitwalker12 / font_helper.rb
Created October 23, 2014 01:06
Importing custom fonts in rails
module ActionView
module Helpers
module AssetUrlHelper
def asset_data_base64(path)
asset = Rails.application.assets.find_asset(path)
throw "Could not find asset '#{path}'" if asset.nil?
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
end
end
@kitwalker12
kitwalker12 / gist:62f09d79f44dd19e2f2e7823f105b79f
Created January 10, 2018 00:07
flatten an array of arbitrarily nested arrays
def flatten_array(arr)
arr.reduce([]) do |res, item|
item.kind_of?(Array) ? res + flatten_array(item) : res << item
end
end
# flatten_array( [[1,2,[3]],4])
@kitwalker12
kitwalker12 / 0000_bundle.config
Last active November 27, 2017 21:24
Sneakers and Sidekiq Configuration on AWS Beanstalk
packages:
yum:
git: []
option_settings:
aws:elasticbeanstalk:application:environment:
BUNDLE_WITHOUT: test:development
0xFCb2654F0Eaf900534C1b4E876b9ED5e00a267c9
@kitwalker12
kitwalker12 / nginx-s3.conf
Created June 22, 2017 21:30
Nginx Proxy for Maintenance Page hosted on S3
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL Optional
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /etc/ssl/my_cert.pem;
ssl_certificate_key /etc/ssl/my_cert.key;
@kitwalker12
kitwalker12 / gist:a9ccdf078c82f844518326067899ba94
Created April 14, 2017 21:19
save and load keys into environment variables from files
// To format a private key into a string literal
cat my_secret.key | sed s/$/\\\\n/ | tr -d '\n'
echo $MY_SECRET_KEY | sed 's/\\n/\n/g' > ~/my_secret.key
@kitwalker12
kitwalker12 / luhn.js
Created April 10, 2017 18:16
luhn algorithm
// Given a positive integer of up to 16 digits, return true if it is a valid credit card number, and false if it is not. Here is the algorithm:
// If there are an even number of digits, double every other digit starting with the first, and if there are an odd number of digits, double every other digit starting with the second. Another way to think about it is, from the right to left, double every other digit starting with the second to last digit.
// 1714 => [1*, 7, 1*, 4] => [2, 7, 2, 4]
// 12345 => [1, 2*, 3, 4*, 5] => [1, 4, 3, 8, 5]
// 891 => [8, 9*, 1] => [8, 18, 1]
// If a resulting doubled number is greater than 9, replace it with either the sum of it's own digits, or 9 subtracted from it.
@kitwalker12
kitwalker12 / circle.yml
Created December 20, 2016 21:57
CircleCI Bundle Config without environments
dependencies:
pre:
- bundle config without development:production
@kitwalker12
kitwalker12 / .0-Rails-Tutum.md
Last active September 14, 2016 17:58
Dockerized Rails on Tutum (Passenger + HAProxy)

How to deploy rails in tutum as a production server behing HAproxy on Passenger

docker build -t 'my_image_name:latest' . && tutum image push my_image_name:latest