2016年5月24日火曜日

heroku postgresql

herokuでDB追加(無料)する方法

heroku login状態で行う

<追加>
heroku addons:add heroku-postgresql:hobby-dev

heroku pg:info --app XXX

psqlで接続
heroku pg:psql DATABASE_URL --app XXX

ログ確認
heroku logs --app XXX -t


いつの間にか--appでアプリ指定が必要になっているかも?

2016年5月19日木曜日

Windows10時刻同期(ntp)

これを行うとよい
Slewモードで設定をする

1.
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient
SpecialPollInterval

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W32Time\Config
UpdateInterval


30分なら10進数で1800に変更する。

2.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Config
MaxAllowedPhaseOffset

10進数で300
Slewのパラメータに影響

3.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Parameters
NtpServer

ntp.nict.jp,0x8
NTPで同期できるっぽい

ntp.nict.jp,0x9
でもよいかもしれない NTP+Winオリジナルのmix?

4.
Windows Time サービスのスタートアップの種類を [手動] から [自動 (遅延開始)] に変更


確認方法
w32tm /query /status

2016年5月5日木曜日

javaで画像操作

主に備忘 画像を新規で作る 線を引くだけ ピクセルを配列変換もする
 public static void main(String[] args) throws IOException {
  BufferedImage img = new BufferedImage(200, 200,
    BufferedImage.TYPE_INT_BGR);
  int w = img.getWidth(null); // Imageの幅
  int h = img.getHeight(null);
  Graphics g = img.getGraphics();
  g.setColor(Color.WHITE); // 白
  g.fillRect(0, 0, w, h);

  g.setColor(Color.BLACK); // 黒
  g.drawLine(10, 10, 100, 100);
  g.dispose();

  ImageIO.write(img, "png", new File("test.png"));

  int[] px = img.getRGB(0, 0, w, h, null, 0, w);

 }

2016年4月19日火曜日

powershellでファイル名変更

powershell を使ったファイル名の変更 正規表現を使って「1.1.あいうえお.txt」というファイル名があった場合には、「1.01.あいうえお.txt」に変更する
@powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 1})-join\"`n\");&$s" %*&goto:eof

$ary=ls|%{$_.name}
foreach($i in $ary){
  if($i -match "^[0-9]\.[0-9]\."){
    Get-ChildItem $i | Rename-Item -NewName { $_.Name -replace '^([0-9])\.([0-9])\.','$1.0$2.' }
  }
}

2015年6月20日土曜日

Javaでクライアント認証の読込み 


Javaでクライアント認証を読込み PKCS#12

証明書は以下を見て作るとよい
http://server-setting.info/centos/apache-ssl-auth-setting.html

下記は、だいたいこんな感じぐらいで
環境を忘れて確認できなくなったので間違っているかも。。。。。

import java.io.FileInputStream;
import java.security.KeyStore;
import java.util.ArrayList;
import java.util.List;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;


public class App
{

    static final String P12FILE = "cert.p12";
    static final char[] PASSWORD = "pass".toCharArray();

    private static SSLContext getSslContext() {
        // PKCS12ファイル読み込み
        KeyManagerFactory keyManagerFactory;
        try (FileInputStream inputStream = new FileInputStream(P12FILE)) {
            KeyStore keyStore = KeyStore.getInstance("PKCS12");
            keyStore.load(inputStream, PASSWORD);

            keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
            keyManagerFactory.init(keyStore, PASSWORD);

            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
            return sslContext;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) throws Exception {
        int socketTimeout = 60000;
        int connectionTimeout = 60000;
        String userAgent = "My Http Client 0.1";
        // request configuration
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(connectionTimeout)
                .setSocketTimeout(socketTimeout)
                .build();
        // headers
        List<Header> headers = new ArrayList<Header>();
        headers.add(new BasicHeader("Accept-Charset", "utf-8"));
        headers.add(new BasicHeader("Accept-Language", "ja, en;q=0.8"));
        headers.add(new BasicHeader("User-Agent", userAgent));
        // create client
        HttpClient httpClient = HttpClientBuilder.create()
                .setDefaultRequestConfig(requestConfig)
                .setDefaultHeaders(headers).setSSLContext(getSslContext())
                .build();

        HttpGet httpGet = new HttpGet("https://mixi.jp/");
        HttpResponse response = httpClient.execute(httpGet);
        int responseStatus = response.getStatusLine().getStatusCode();
        String body = EntityUtils.toString(response.getEntity(), "UTF-8");
        System.out.println(body);
    }
}

2015年1月20日火曜日

某ソース


import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.commons.beanutils.PropertyUtils;

public class Test {

 static Map, Map> relationMap = new HashMap, Map>();
 static Map, Serializable>> seachResult = new HashMap, Serializable>>();
 static Map> endEntity = new HashMap>();

 static {
  List list = new ArrayList();
  Map map2 = new HashMap();
  relationMap.put(list, map2);
  list.add("led");
  list.add("m");
  list.add("r");
  map2.put("m", "m");
  map2.put("c", "c");
 }

 public static void main(String[] args) {
  try {

   List searchList = new ArrayList();
   for (Serializable serializable : searchList) {
    loadRoleEntity(serializable);
   }
  } catch (Exception e1) {
   e1.printStackTrace();
  }
 }

 private static void loadRoleEntity(Serializable serializable)
   throws Exception {
  Set idSet = endEntity.get(serializable.getClass().getCanonicalName());
  if (idSet == null) {
   idSet = new HashSet();
   endEntity.put(serializable.getClass().getCanonicalName(), idSet);
  }
  if (idSet.contains(serializable.getId())) {
   return;
  }
  Set targets = getNextTarget(serializable.getClass().getCanonicalName());
  if (targets.isEmpty()) {
   return;
  }
  for (String target : targets) {
   List> relation = getParentMap(serializable.getClass().getCanonicalName(), target);
   List> foreginKeyValuMapList = new ArrayList>();
   for (Set set : relation) {
    Map hashMap = new HashMap();
    for (String key : set) {
     Object property = PropertyUtils.getProperty(serializable, key);
     hashMap.put(key, (Serializable) property);
    }
    foreginKeyValuMapList.add(hashMap);
   }

   List searched = searchTarget(target, foreginKeyValuMapList);
   Map> keysMap = getChildMap(serializable.getClass().getCanonicalName(),
     target);
   if (searched != null) {
    Map, Serializable> hashMap2 = new HashMap, Serializable>();
    seachResult.put(target, hashMap2);

    Map hashMap = new HashMap();
    for (Serializable serializable2 : searched) {
     for (Entry> e : keysMap.entrySet()) {
      Map keys = e.getValue();
      for (Entry e2 : keys.entrySet()) {
       Object property = PropertyUtils.getProperty(serializable2, e2.getValue());
       hashMap.put(e2.getKey(), (Serializable) property);
      }
      hashMap2.put(hashMap, serializable2);
     }
    }
   }

   Set keySet = keysMap.keySet();
   for (String key : keySet) {
    List keyList = new ArrayList();
    keyList.add(serializable.getClass().getCanonicalName());
    keyList.add(key);
    keyList.add(target);
    Map map2 = relationMap.get(keyList);
    Map, Serializable> searchResultMap = seachResult.get(target);
    Serializable serializable2 = searchResultMap != null ? searchResultMap.get(map2) : null;
    Field declaredField = serializable.getClass().getDeclaredField(key);
    declaredField.setAccessible(true);
    if (Set.class.equals(declaredField)) {
     Set set = (Set) PropertyUtils.getProperty(serializable, key);
     if (set == null) {
      set = new HashSet();
      PropertyUtils.setProperty(serializable, key, set);
     }
     if (serializable2 != null) {
      set.add(serializable2);
     }
    }
    else {
     PropertyUtils.setProperty(serializable, key, serializable2);
    }
   }

   for (Serializable serializable2 : searched) {
    loadRoleEntity(serializable2);
   }

  }
 }

 private static Map> getChildMap(String canonicalName, String target) {
  Map> result = new HashMap>();
  for (Entry, Map> e : relationMap.entrySet()) {
   List list = e.getKey();
   if (list.get(0).equals(canonicalName) &&
     list.get(2).equals(canonicalName)) {
    Map set = result.get(list.get(1));
    if (set == null) {
     set = new HashMap();
     result.put(list.get(1), e.getValue());
    }
   }
  }

  return result;
 }

 private static List searchTarget(String target, List> foreginKeyValuMapList) {
  return null;

 }

 private static Set getNextTarget(String canonicalName) {
  Set result = new HashSet();
  Set> keySet = relationMap.keySet();
  for (List list : keySet) {
   if (list.get(0).equals(canonicalName)) {
    result.add(list.get(2));
   }
  }
  return result;
 }

 private static List> getParentMap(String canonicalName, String target) {
  List> result = new ArrayList>();
  for (Entry, Map> e : relationMap.entrySet()) {
   List list = e.getKey();
   if (list.get(0).equals(canonicalName) &&
     list.get(2).equals(canonicalName)) {
    Set keySet = e.getValue().keySet();
    result.add(keySet);
   }
  }

  return result;
 }
}

2014年11月12日水曜日

VMwareにてandroidインストール時の解像度

Vmwareにてandroidをインストールして解像度を変更したいとき

デバッグモードにて起動
# mount -o remount,rw /mnt
# vi /mnt/grub/menu.lst
引数の最後にvga=794とつけると1280×1024になる
vga=askとつけると一覧で確認したうえで選択できる模様