This file contains 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
#!/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 |
This file contains 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
#!/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 |
This file contains 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
text = " | |
/* | |
* multi-line comment block | |
*/ | |
void main() { | |
/* single-line comment block */ | |
}" | |
puts text.gsub(/\/\*(?:(?!\*\/).)*\*\//m, '') |
This file contains 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
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): |
This file contains 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 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): |
This file contains 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
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>', |
This file contains 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
Hoge p = new Hoge(); | |
p.code = '0001'; | |
p.name = 'hogename1'; | |
p.items = new List<HogeItem>{ | |
new HogeItem('0001-01', 'item001'), | |
new HogeItem('0001-02', 'item002') | |
}; | |
JSONGenerator jg = JSON.createGenerator(false); | |
jg.writeObject(p); |
This file contains 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 getValue(key, items): | |
""" | |
Get value from list of dict that has "Key" and "Value" key. | |
""" | |
values = [x['Value'] for x in items if 'Key' in x and 'Value' in x and x['Key'] == key] | |
return values[0] if values else None | |
# 使用例 | |
items = [{'Key': 'Name', 'Value': 'apple'}, |
This file contains 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
import boto3 | |
from datetime import datetime | |
def get_events(log_group_name, log_stream_name, region_name=None): | |
""" | |
Get all event messages of a group and stream from CloudWatch Logs AWS | |
""" | |
client = boto3.client('logs', region_name=region_name) |
This file contains 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
exports.handler = async (event) => { | |
event.Records.map(({kinesis}) => { | |
const payload = Buffer.from(kinesis.data, 'base64').toString(); | |
outputlog(JSON.parse(payload)); | |
}); | |
return {statusCode: 200}; | |
}; | |
function outputlog({EventType, EventTimestamp, CurrentAgentSnapshot}) { | |
if (EventType === 'HEART_BEAT') return; |
OlderNewer