Skip to content

Instantly share code, notes, and snippets.

View mryoshio's full-sized avatar

YOSHIOKA A mryoshio

View GitHub Profile
@mryoshio
mryoshio / build POST using Apache HttpComponents
Created August 22, 2011 06:09
build POST request which has multipart body (String and Image)
private HttpPost buildPostRequest(String _method, String _path, Map _params)
throws ServerConnectionException {
HttpPost request = new HttpPost();
try {
request.setURI(URIUtils.createURI(scheme, host, port, _path, null,
null));
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
@mryoshio
mryoshio / get image using Apache HttpComponents
Created August 22, 2011 06:10
get image and process into byte[]
private byte[] requestImage(String path) throws ServerConnectionException {
BufferedInputStream inStream = null;
try {
HttpResponse response = client.execute(buildGetRequest(
HttpGet.METHOD_NAME, path, new HashMap()));
HttpEntity entity = response.getEntity();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
if (entity == null) {
return new byte[0];
@mryoshio
mryoshio / getRequestWithApacheHttpComponents
Created August 22, 2011 07:00
build GET request using Apache HttpComponents
private HttpGet buildGetRequest(String _method, String _path, Map _params)
throws ServerConnectionException {
List params = new ArrayList();
for (Iterator it = _params.keySet().iterator(); it.hasNext();) {
String k = (String) it.next();
params.add(new BasicNameValuePair(k, (String) _params.get(k)));
}
HttpGet request = new HttpGet();
@mryoshio
mryoshio / CmisSampleClient.java
Created December 12, 2011 07:01
CMIS sample client code using Apache Chemistry
/**
* This code uses Apache Chemistry (http://chemistry.apache.org/).
* License accords to Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@mryoshio
mryoshio / importFromLDAP.java
Created April 4, 2012 03:10
LDAP Client test (import user)
/**
* This program is under LGPL v2.1 as Liferay.
*/
package jp.hoge.liferay.experiment.ldap;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
@mryoshio
mryoshio / pymysql_sample_update.py
Created April 4, 2012 09:41
Update many records all at once using pymysql module.
def main():
"""
Execute three actions.
1. get id, new title from a file. e.g. [(title, id),(title, id)]
2. update DB
"""
id_titles = get_id_titles(EXPECTED_LIST)
conn = pymysql.Connect(host=DB_HOST, db=DB, user=DB_USER, passwd=DB_PSWD, charset=CHARSET)
cursor = conn.cursor()
@mryoshio
mryoshio / array_stack.py
Created April 28, 2013 13:32
use an array for 3 stacks
STACK_SIZE = 10
class ArrayStack:
"""
This class realize 3 stacks in 1 array.
"""
def __init__(self):
self.buffer = [0] * STACK_SIZE * 3
self.stack_pointer = [-1, -1, -1]
@mryoshio
mryoshio / test_group.py
Last active December 17, 2015 05:39
unittest example for Python
import unittest
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import testbed
from model import Group
class GroupTestCase(unittest.TestCase):
@mryoshio
mryoshio / dot_travis_sample.yml
Created May 11, 2013 09:01
.travis.yml example for Google App Engine/Python
language: python
python:
- '2.7'
install:
- 'pip install -r requirements.txt --use-mirrors'
before_script:
- wget http://googleappengine.googlecode.com/files/google_appengine_1.8.0.zip -nv
@mryoshio
mryoshio / method.rb
Created May 25, 2013 14:39
Method practice.
# dynamic dispatch
puts '##### dynamic dispatch'
class Student
def initialize
@name = 'Joe'
end
def original
"#{@name}'s original score: { math: 60, eng: 56 }"