Instantly share code, notes, and snippets.

@takuo
takuo / gist:282683
Created Jan 21, 2010
mime decode for ruby1.9
View gist:282683
# mime decode for ruby 1.9
def mime_decode( input, out_charset = 'utf-8' )
while input.sub!(/(=\?[A-Za-z0-9_-]+\?[BQbq]\?[^\?]+\?=)(?:(?:\r\n)?[\s\t])+(=\?[A-Za-z0-9_-]+\?[BQbq]\?[^\?]+\?=)/, '\1\2')
end
begin
ret = input.sub!( /=\?([A-Za-z0-9_-]+)\?([BQbq])\?([^\?]+)\?=/ ) {
charset = $1
enc = $2.upcase
word = $3
word = word.unpack( { "B"=>"m*", "Q"=>"M*" }[enc] ).first
View coincheck_market_price.10s.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"
)
@takuo
takuo / OAuthVerify.java
Created Oct 20, 2011
Android code snippet - OAuth verifier process (with Twitter4J)
View OAuthVerify.java
public class OAuthVerify extends Activity {
private static final String CONSUMER_KEY = "";
private static final String CONSUMER_SECRET = "";
private static final String CALLBACK_URL = "myoauthapp://oauthcallback/";
private Context mContext;
private WebView mWebView;
private Twitter mTwitter;
private RequestToken mRequestToken;
private AccessToken mAccessToken;
@takuo
takuo / nmagw.rb
Created Dec 29, 2012
nma http gateway
View nmagw.rb
# -*- coding: utf-8 -*-
require 'oauth'
require 'json'
require 'sinatra/base'
require 'net/http'
class NmaGw < Sinatra::Base
set :logging, true
@takuo
takuo / amazonlink.user.js
Created Sep 26, 2012
アマゾンの商品リンクコピペ用
View amazonlink.user.js
@takuo
takuo / AndroidManifest.xml
Created Mar 6, 2012
共有(Intent.ACTION_SEND)で受け取ったテキストをクリップボードにぶち込むだけのアプリ
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.takuo.android.sharetoclipboard"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" />
<application
android:icon="@drawable/ic_launcher"
@takuo
takuo / AndroidManifest.xml
Created Feb 28, 2012
twicca plugin - share a status url
View AndroidManifest.xml
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:theme="@android:style/Theme.Translucent">
<activity
android:label="@string/activity_name"
android:name=".TweetLinkShare">
<intent-filter>
<action android:name="jp.r246.twicca.ACTION_SHOW_TWEET" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@takuo
takuo / gist:1294790
Created Oct 18, 2011
Android code snippet - using Thread
View gist:1294790
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
final Bitmap bitmap = loadImageFromNetwork("http://example.com/image.png");
mImageView.post(new Runnable() {
public void run() {
mImageView.setImageBitmap(bitmap);
}
});
}
@takuo
takuo / gist:1294791
Created Oct 18, 2011
Android code snippet - using AsyncTask
View gist:1294791
public void onClick(View v) {
new DownloadImageTask().execute("http://example.com/image.png");
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
/** The system calls this to perform work in a worker thread and
* delivers it the parameters given to AsyncTask.execute() */
protected Bitmap doInBackground(String... urls) {
return loadImageFromNetwork(urls[0]);
}
@takuo
takuo / MyActivity.java
Created Oct 18, 2011
Android code snippet - using IntentService
View MyActivity.java
public void onClick(View v) {
startService(new Intent(this, MyService.class));
}