Skip to content

Instantly share code, notes, and snippets.

View ardeearam's full-sized avatar
💭
https://blog.klaudsol.com

Ardee Aram ardeearam

💭
https://blog.klaudsol.com
View GitHub Profile
# 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 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
# 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'
# 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|
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
# 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
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
@ardeearam
ardeearam / efficientWatch.js.coffee
Last active February 10, 2016 04:59
An alternative to $scope.$watch
'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.
@ardeearam
ardeearam / .vimrc
Last active February 22, 2016 05:31
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
queue = Sidekiq::RetrySet.new
jobs = queue.select{|job| job.klass == "AppointmentRepeater"}
jobs.each(&:delete)