Skip to content

Instantly share code, notes, and snippets.

View shinsaka's full-sized avatar
✍️
Writing python 🔥

Manabu Shinsaka shinsaka

✍️
Writing python 🔥
View GitHub Profile
@shinsaka
shinsaka / testListObjectFromS3.rb
Last active September 3, 2017 09:08
S3 list_objets "max_keys" behavior test with AWS SDK V2 for Ruby
require 'aws-sdk'
def get_object_list(max_num)
options = {
region: 'ap-northeast-1',
access_key_id: 'AKI*****************',
secret_access_key: '****************************************'
}
Aws::S3::Client.new(options).list_objects(
bucket: '<YOUR-BUCKET-NAME>',
@shinsaka
shinsaka / ajax_required_decorator.py
Last active June 9, 2016 15:36
Decorator for determing whether the request is Ajax, in Django-views.
def ajax_required(ret_unexcepted):
"""
Decorator for determing whether the request is Ajax, in Django-views.
e.g.) in views.py
from django.http import HttpResponseBadRequest
from utils.decorators import ajax_required
@ajax_requirxed(HttpResponseBadRequest())
def index(request):
@shinsaka
shinsaka / redirect_correct_hostname_middleware.py
Created May 30, 2016 12:35
redirects to correct hostname if requested hostname and settings.CORRECT_HOST does not match
from django.http import HttpResponsePermanentRedirect
from django.conf import settings
class RedirectCorrectHostname(object):
"""
redirects to correct hostname if requested hostname and settings.CORRECT_HOST does not match
(at heroku domain redirects to custom domain)
"""
def process_request(self, request):
if not getattr(settings, 'CORRECT_HOST', None):
@shinsaka
shinsaka / replace comment block
Created February 2, 2016 03:30
Replace C like comment block sample
text = "
/*
* multi-line comment block
*/
void main() {
/* single-line comment block */
}"
puts text.gsub(/\/\*(?:(?!\*\/).)*\*\//m, '')
@shinsaka
shinsaka / rds_ri_prices_parser.rb
Last active September 17, 2019 04:14
AWS RDS RI pricing parser
#!/usr/bin/env ruby
require 'json'
def parse(uri)
JSON.parse `curl -s #{uri}`.gsub(/\/\*(?:(?!\*\/).)*\*\//m, '').strip.gsub(/^callback\(/, '').gsub(/\);/, '').gsub(/([a-zA-Z]+[0-9]*):/, '"\1":')
end
puts %w(
platform
@shinsaka
shinsaka / parse.rb
Last active April 18, 2017 10:35 — forked from tatsuru/parse.rb
ec2 RI parser
#!/usr/bin/env ruby
require 'json'
def parse(uri)
JSON.parse `curl -s #{uri}`.gsub(/\/\*.*\*\/\s*callback\(\{/m,'{').gsub("\);", '').gsub(/([a-zA-Z]+):/, '"\1":')
end
puts %w(
platform