Skip to content

Instantly share code, notes, and snippets.

View thapakazi's full-sized avatar
💭
🐧 🗡️ 💻

Milan Thapa thapakazi

💭
🐧 🗡️ 💻
View GitHub Profile
@thapakazi
thapakazi / README.md
Created April 5, 2018 18:45 — forked from bigglesrocks/README.md
Rails Scoped Invitation System

#Scoped Invitation System for User Groups with Rails#

Starting out with the following models and associations:

####User

  • has_many :memberships
  • has_many :organizations through :memberships

####Organization (User Group)

  • has_many :memberships
@thapakazi
thapakazi / AWSRegionsAndAZs.md
Created March 13, 2018 03:10
List of AWS availability zones for each AWS region
AWS region code AWS region name Number of AZs AZ names
us-east-1 Virginia 4 us-east-1a, us-east-1b, us-east-1c, us-east-1e
us-west-1 N. California 2 us-west-1a, us-west-1b
us-west-2 Oregon 3 us-west-2a, us-west-2b, us-west-2c
eu-west-1 Ireland 3 eu-west-1a, eu-west-1b, eu-west-1c
eu-central-1 Frankfurt 2 eu-central-1a, eu-central-1b
ap-southeast-1 Singapore 2 ap-southeast-1a, ap-southeast-1b
ap-southeast-2 Sydney 2 ap-southeast-2a, ap-southeast-2b, ap-southeast-2c
ap-northeast-1 Tokyo 2 ap-northeast-1a, ap-nort
@thapakazi
thapakazi / Procfile
Created January 13, 2018 06:11 — forked from andrius/Procfile
How to dockerize rails app with puma. Edit config/application.rb and config/puma.rb
api: bundle exec puma -C config/puma.rb
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid
@thapakazi
thapakazi / kubectl.md
Created September 18, 2017 16:43 — forked from so0k/kubectl.md
Playing with kubectl output

Kubectl output options

Let's look at some basic kubectl output options.

Our intention is to list nodes (with their AWS InstanceId) and Pods (sorted by node).

We can start with:

kubectl get no
@thapakazi
thapakazi / bash-random-lines-test.sh
Created July 20, 2017 18:39 — forked from pavlov99/bash-random-lines-test.sh
sample random lines from file in bash, benchmark
#!/bin/bash
FILENAME="/tmp/random-lines.$$.tmp"
NUMLINES=10000000
seq -f 'line %.0f' $NUMLINES > $FILENAME;
echo "10 random lines with nl:"
$(which time) -v nl -ba $filename | sort -r | sed 's/.*[0-9]\t//' | head > /dev/null
echo "10 random lines with shuf:"
$(which time) -v shuf $FILENAME -n10 | head > /dev/null
@thapakazi
thapakazi / get_twitter_oauth2_token.sh
Created July 15, 2017 11:25 — forked from RouxRC/get_twitter_oauth2_token.sh
Get an application-type OAuth2 token from Twitter in bash
#!/bin/bash
# Run with:
#
# bash get_twitter_oauth2_token.sh $KEY $SECRET > oauth2_token
#
# Then enjoy Twitter's API app functions such as search/tweets or lists/members:
#
# curl -H "$(cat oauth2_token)" "https://api.twitter.com/1.1/search/tweets.json?q=assembleenat+OR+deputes&count=200"
# curl -H "$(cat oauth2_token)" "https://api.twitter.com/1.1/lists/members.json?slug=les-d%C3%A9put%C3%A9s&owner_screen_name=AssembleeNat&skip_status=1"
@thapakazi
thapakazi / postgres_queries_and_commands.sql
Created July 13, 2017 03:45 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@thapakazi
thapakazi / nginxproxy.md
Created July 12, 2017 11:16 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@thapakazi
thapakazi / README.md
Created July 11, 2017 02:52 — forked from alexellis/README.md
Live Stream to YouTube from your RPi with Docker

Live Stream to YouTube from your RPi with Docker

Normally ffmpeg needed to stream to YouTube takes 8-9 hours to build on a PiZero. You can download my image here and run it with your secret key:

docker run --privileged -ti alexellis2/streaming:17-5-2017 <secret>

Bill of materials: