This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Input: Apache2 access log | |
# Output: IP Address, and number of access, in descending order | |
# Use Case: When there are strong reasons to believe that you are being DDOS'ed, you can see the top X IP's that | |
# access the site, and choose to ban them. | |
begin | |
ips = {} | |
while a = gets.chomp | |
ip = a.split(" ")[0] | |
#puts ip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is how to iterate over Amzon SDK version 2. | |
# Notice that the actual data is contained inside the "data" method. | |
# This is the one that got me, and this is not documented anywhere. | |
sqs = Aws::SQS::Client.new(region: 'ap-southeast-1') | |
output ="" | |
sqs.list_queues.each do |response| | |
output += response.data.to_json + "\n" | |
end | |
puts output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you are running JRuby, and want to access AWS SQS via the AWS-SDK for Java, | |
# it's not as straightforward as it seems. There are JAR dependencies that need to be met | |
# before you can invoke SQS. | |
require 'java' | |
require 'jar/aws-java-sdk-1.9.20.1.jar' | |
require 'jar/commons-logging-1.2.jar' | |
require 'jar/jackson-databind-2.3.1.jar' | |
require 'jar/jackson-core-2.5.0.jar' | |
require 'jar/jackson-annotations-2.5.0.jar' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference: http://stackoverflow.com/questions/28351438/cannot-create-a-bucket-in-s3-using-ruby-aws-sdk-v2 | |
s3 = Aws::S3::Client.new(region: region, credentials: credentials) | |
bucket = s3.create_bucket(bucket: 'mynewbucket') | |
puts bucket.inspect | |
# List the available buckets | |
puts "Available buckets:" | |
resp = s3.list_buckets | |
resp.buckets.each do |bucket| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sns | |
logger.debug request.raw_post | |
request_json = JSON.parse(request.raw_post, {symbolize_names: true}) | |
subscribe_url = request_json[:SubscribeURL] | |
logger.debug subscribe_url | |
#Fire up your favorite REST or CURL client, and visit subscribe_url | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to create an alias `git lg` that displays a pretty, colored tree by default. | |
git config alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset [%an]' --abbrev-commit" --global |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ReferralDocument.each do |r| | |
begin | |
referral_master = Referral.find(r.referral_id) | |
r.update(service_id: referral_master.master_service.id, reference: referral_master.reference) | |
rescue ActiveRecord::RecordNotFound => ex1 | |
puts ex1.class.name + " " + ex1.message + ". Deleting mongo Referral cache..." | |
r.destroy | |
rescue StandardError => ex2 | |
puts ex2.class.name + " " + ex2.message | |
r.destroy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
#Usage: | |
# efficientWatch.watch 'someProperty', ctrl, (newValue, oldValue) -> | |
# console.log("As good as $scope.$watch, without the digest tax!") | |
#Source: http://www.jomendez.com/2015/02/25/optimizing-code-object-defineproperty-scope-watch-angularjs/ | |
#With my own changes: | |
# 1.) The attribute name is generic | |
# 2.) The callback function (3rd parameter) is passed with the oldValue as the second parameter, to mimic $scope.$watch better. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
execute pathogen#infect() | |
syntax on | |
set number | |
set ruler | |
set noswapfile | |
set runtimepath^=~/.vim/bundle/ctrlp.vim | |
set tabstop=2 | |
set shiftwidth=2 | |
set expandtab | |
set nosmartindent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
queue = Sidekiq::RetrySet.new | |
jobs = queue.select{|job| job.klass == "AppointmentRepeater"} | |
jobs.each(&:delete) |
OlderNewer