Skip to content

Instantly share code, notes, and snippets.

View kitwalker12's full-sized avatar

Kunwar Aditya Raghuwanshi kitwalker12

View GitHub Profile
@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 / migrate-redis.py
Created March 4, 2017 00:11 — forked from thomasst/migrate-redis.py
Migrate Redis data on Amazon ElastiCache
"""
Copies all keys from the source Redis host to the destination Redis host.
Useful to migrate Redis instances where commands like SLAVEOF and MIGRATE are
restricted (e.g. on Amazon ElastiCache).
The script scans through the keyspace of the given database number and uses
a pipeline of DUMP and RESTORE commands to migrate the keys.
Requires Redis 2.8.0 or higher.
@kitwalker12
kitwalker12 / circle.yml
Created December 20, 2016 21:57
CircleCI Bundle Config without environments
dependencies:
pre:
- bundle config without development:production
@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
@kitwalker12
kitwalker12 / get_crontabs.sh
Created August 3, 2016 00:08
See crontabs for all users on linux (ubuntu)
for user in $(getent passwd | cut -f1 -d: ); do echo $user; crontab -u $user -l; done
@kitwalker12
kitwalker12 / readme.md
Last active May 17, 2016 20:41
US Zip Code regex. Regex to find allowed prefixes for US Zipcodes minus Military Bases
  • Regex generated via frak in clojure

  • Install clojure and leiningen brew install leiningen

  • Create new app lein new app frakproj

  • cd into new directory frakproj

  • edit project.clj to add [frak "0.1.6"] as dependency. the new file should look like this:

    (defproject frakproj "0.1.0-SNAPSHOT"
    :description "FIXME: write description"
    :url "http://example.com/FIXME"
    
@kitwalker12
kitwalker12 / replace.sh
Created May 9, 2016 18:39
replace words in all files on Mac OSX
LC_ALL=C find ./ -name "{filter}" -type f -exec sed -i '' -e 's/{old-word}/{new-word}/g' {} \;
@kitwalker12
kitwalker12 / crontab -e
Created April 27, 2016 17:11
S3 Backup locally script (use absolute paths for files)
0 21 * * * s3backup.sh >> crontab.out 2> crontab.err &
0 5 * * * s3stopbackup.sh >> crontab.out 2> crontab.err &