Skip to content

Instantly share code, notes, and snippets.

@wbingli
wbingli / replace.sh
Created July 16, 2014 23:32
Replace ${} placeholder with environment values
perl -p -i -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg' $1

In a perfect world, where things are done well, not just quickly, I would expect to find the following when joining the company:

Documentation

  • Accurate / up-to-date systems architecture diagram

  • Accurate / up-to-date network diagram

  • Out-of-hours support plan

  • Incident management plan

@wbingli
wbingli / mac_add_loopback_ip
Created September 9, 2014 21:24
Add a new loopback ip. Mac only has one loopback ip(127.0.0.1) while Linux use 127.0.0.0/8 for loopback address.
sudo ifconfig lo0 alias 127.0.0.2 up
@wbingli
wbingli / pr.md
Last active August 29, 2015 14:07 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

require 'json'
$access_token = <your own token>
def add_word(word)
puts "Checking word : #{word}"
begin
result = `curl https://api.shanbay.com/bdc/search/?word=#{word}&access_token=#{$access_token}`
result = JSON.parse(result)
word_id = result['data']['id']
word_learning_id = result['data']['learning_id']
puts " word #{word}; id : #{word_id} ; learning_id: #{word_learning_id}"
@wbingli
wbingli / aws_ips.rb
Created October 28, 2015 20:49
Calculate AWS total IPs
require 'open-uri'
require 'json'
data = JSON.load(open("https://ip-ranges.amazonaws.com/ip-ranges.json"))
ip_total = data['prefixes'].reduce(0) do | sum, item |
sum += 2 ** (32 - item['ip_prefix'].split('/')[1].to_i)
end
puts "AWS Total IPs: #{ip_total}"
{
"autoscaling": {
"CreateAutoScalingGroup": "autoscaling:CreateAutoScalingGroup",
"CreateLaunchConfiguration": "autoscaling:CreateLaunchConfiguration",
"CreateOrUpdateScalingTrigger": "autoscaling:CreateOrUpdateScalingTrigger",
"CreateOrUpdateTags": "autoscaling:CreateOrUpdateTags",
"DeleteAutoScalingGroup": "autoscaling:DeleteAutoScalingGroup",
"DeleteLaunchConfiguration": "autoscaling:DeleteLaunchConfiguration",
"DeleteNotificationConfiguration": "autoscaling:DeleteNotificationConfiguration",
"DeletePolicy": "autoscaling:DeletePolicy",

AWS::Logs::LogGroup

Resource schema for AWS::Logs::LogGroup

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON