Skip to content

Instantly share code, notes, and snippets.

View KazuyaHayashi's full-sized avatar

林 和哉 KazuyaHayashi

  • 日本
  • 東京都
View GitHub Profile
@KazuyaHayashi
KazuyaHayashi / OAuth2_app.py
Created November 26, 2012 01:51
OAuth2 Web Server sample
import base64
import logging
import simplejson as json
import os
import datetime
import functools
import gdata.apps.service
import gdata.apps.client
import gdata.auth
import gdata.gauth
@KazuyaHayashi
KazuyaHayashi / all_userfeed.py
Created November 26, 2012 01:59
OAuth2 Service Accounts sample
import logging
import json
#logging.basicConfig(level=logging.DEBUG)
from oauth2client import client
import gdata.apps.service
from jwt_util import get_JWT, get_service_private_key, get_clientSecrets
@KazuyaHayashi
KazuyaHayashi / browser.py
Created November 26, 2012 09:10
parse user-agent.
import re
class BrowserDetector(object):
def __init__(self):
self.patterns = [
'.*(?P<browser>(MSIE|msie)) (?P<version>[0-9.]+).*',
'.* (VERSION|version)/(?P<version>[0-9.]+) (?P<browser>(SAFARI|safari))/.*',
'.*(?P<browser>(CHROME|chrome))/(?P<version>[0-9.]+).*',
'.*(?P<browser>(FIREFOX|firefox))/(?P<version>[0-9.]+).*',
]
@KazuyaHayashi
KazuyaHayashi / UnreadMessageCounter.py
Created November 30, 2012 05:36
IMAP with XOAuth2 and Gmail Inbox Feed with OAuth2
#!/usr/bin/env python2.6
import base64
import sys
import json
import imaplib
import urllib
from optparse import OptionParser
import atom.http_core
@KazuyaHayashi
KazuyaHayashi / util.py
Created February 6, 2013 02:36
utility for google api XML feed.
import functools
import logging
from django.utils import simplejson
def get_json_from_feed(user_feed):
"""Constructs and returns a JSON object from the given feed object
Args:
user_feed: A gdata.apps.UserFeed object
@KazuyaHayashi
KazuyaHayashi / jwtutils.py
Created February 7, 2013 02:44
utility for JWT.
import base64
import json
import urllib
import atom.http_core
from oauth2client import client
class Error(Exception):
def __str__(self):
return "Error: %s" % self.error_message
@KazuyaHayashi
KazuyaHayashi / application.py
Last active December 12, 2015 06:29
get login user's information by OAuth2 Authentication. check user is admin by access to provisioning API with JWT.
import flask
import logging
import json
from flask import request, redirect
import gdata.gauth
import gdata.apps.service
import gdata.apps.groups.service
import gdata.auth
from gdata.apps.service import AppsForYourDomainException
$scope.safeApply = function(fn) {
var phase = this.$root.$$phase;
if(phase == '$apply' || phase == '$digest')
this.$eval(fn);
else
this.$apply(fn);
};
// OR
--langdef=js
--langmap=js:.js
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*\{/\5/,object/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*function[ \t]*\(/\5/,function/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*\[/\5/,array/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*[^"]'[^']*/\5/,string/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*(true|false)/\5/,boolean/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*[0-9]+/\5/,number/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*.+([,;=]|$)/\5/,variable/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*[ \t]*([,;]|$)/\5/,variable/
@KazuyaHayashi
KazuyaHayashi / test_switch_role.py
Last active January 13, 2016 09:30
Test script for delegation cross account access by switching IAM Role.
import boto3
import random
class S3(object):
def __init__(self, credentials=None):
if credentials:
self.resource = boto3.resource('s3',
aws_access_key_id=credentials['AccessKeyId'],
aws_secret_access_key=credentials['SecretAccessKey'],