Skip to content

Instantly share code, notes, and snippets.

@hnaohiro
hnaohiro / go-twitter
Last active September 13, 2019 12:13
GolangでTwitter OAuthを使うサンプル
package main
import (
"fmt"
"log"
"io/ioutil"
"encoding/json"
"github.com/mrjones/oauth"
)
@hnaohiro
hnaohiro / python-smtp
Created January 19, 2013 10:47
Gmailでメール送信をPythonで
#!/usr/bin/env python
import sys
from optparse import OptionParser
import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate
@hnaohiro
hnaohiro / go-unzip
Created January 19, 2013 13:01
Golangでzipファイルを解凍するサンプル
package main
import (
"archive/zip"
"io"
"log"
"os"
"path/filepath"
)
@hnaohiro
hnaohiro / java-googlechart
Last active December 11, 2015 08:19
JavaでGoogle Char APIから図を作成するサンプル
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
public class GoogleChart {
/** Googleから画像を取得 */
public ImageIcon get(Map<String, String> params) throws IOException {
Object[] keys = params.keySet().toArray();
@hnaohiro
hnaohiro / go-iconv
Created January 19, 2013 13:51
Golangでincovを使うサンプル
package main
/*
#include <stdlib.h>
#include <iconv.h>
#cgo LDFLAGS: -liconv
*/
import "C"
import (
"unsafe"
@hnaohiro
hnaohiro / go-http
Last active December 11, 2015 08:28
Golangでcookie機能付きhttpclient
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
type Jar struct {
@hnaohiro
hnaohiro / ruby-userstream
Created January 20, 2013 22:09
RubyでUserStreamsを使うサンプル
require 'tweetstream'
TweetStream.configure do |config|
config.consumer_key = '********'
config.consumer_secret = '********'
config.oauth_token = '********'
config.oauth_token_secret = '********'
config.auth_method = :oauth
end
@hnaohiro
hnaohiro / autopost-hatenablog
Created January 23, 2013 21:01
はてなブログへの投稿プログラム
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'mechanize'
username = '****'
password = '****'
agent = Mechanize.new
@hnaohiro
hnaohiro / go-urlencode
Created January 24, 2013 20:57
Golang URL Encode
func urlencode(s string) (result string){
for _, c := range(s) {
if c <= 0x7f { // single byte
result += fmt.Sprintf("%%%X", c)
} else if c > 0x1fffff {// quaternary byte
result += fmt.Sprintf("%%%X%%%X%%%X%%%X",
0xf0 + ((c & 0x1c0000) >> 18),
0x80 + ((c & 0x3f000) >> 12),
0x80 + ((c & 0xfc0) >> 6),
0x80 + (c & 0x3f),
@hnaohiro
hnaohiro / struct2map.go
Created January 24, 2013 21:35
Golangでreflectを使ってstructからmapへ変換
package main
import (
"fmt"
"reflect"
)
func StructToMap(data interface{}) map[string]interface{} {
result := make(map[string]interface{})
elem := reflect.ValueOf(data).Elem()