Skip to content

Instantly share code, notes, and snippets.

View tanaka-takayoshi's full-sized avatar

tanaka_733 tanaka-takayoshi

View GitHub Profile
@tanaka-takayoshi
tanaka-takayoshi / pom.xml
Created March 18, 2012 13:19
Current configuration file for cloudfoundry / vcap-java-client / cloudfoundry-maven-plugin .
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.cloudfoundry.samples</groupId>
<artifactId>hello-java</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
else if (expression.indexOf("=>") == -1)
{
return new Function("$,$$,$$$,$$$$", "return " + expression).bind(Enumerable);
}
else
{
var expr = expression.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/);
return new Function(expr[1], "return " + expr[2]);
}
@tanaka-takayoshi
tanaka-takayoshi / UnzipImagesFromXLSX.ps1
Created July 23, 2012 00:24
Extract attached media files from an xlsx file
$sh = new-object -com shell.application
$path = $args[0]
$targetfolder = Split-Path $path -parent
$zipFile = [System.IO.Path]::ChangeExtension($path,".zip")
Copy-Item $path $zipFile
$sh.namespace($zipFile).ParseName("xl\media\") | % { $sh.namespace($targetfolder).copyhere($_.Path) }
Remove-Item $zipFile
Join-Path $targetfolder "media" | Invoke-Item
@tanaka-takayoshi
tanaka-takayoshi / DistanceCalc.cs
Created September 10, 2012 09:29
GetDistance between two points in Windows Phone SDK
public static class DistanceCalc
{
/// <summary>
/// 長半径(赤道半径) at WGS84 (GPS)
/// </summary>
private const double equationalRaius = 6378137.000;
/// <summary>
/// 短半径(極半径) at WGS84 (GPS)
/// </summary>
private const double polarRadius = 6356752.314245;
@tanaka-takayoshi
tanaka-takayoshi / propb.snippet
Created September 23, 2012 06:34
VS2012 のテンプレートにある BindableBase を実装したクラスのプロパティを書くためのスニペット
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>BindableProperty を定義します</Title>
<Shortcut>propb</Shortcut>
<Description>DependencyProperty をバッキング ストアとして使用するプロパティのコード スニペット</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@tanaka-takayoshi
tanaka-takayoshi / ColorViewModel.cs
Created January 12, 2013 16:36
List all the colors defined as public static properties in Colors class and your phone's accent color. ColorViewModel is my defined class.
public class ColorViewModel
{
public ColorViewModel(string text, Color color)
{
this.Text = text;
this.Color = color;
this.ColorBrush = new SolidColorBrush(color);
}
public string Text { get; set; }
public Color Color { get; set; }
protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
var cli = await Client.ConnectClient();
var user = await cli.GetMe();
var quota = await cli.GetStorageQuota();
userText.Text = user.Name != null ? string.Format("ようこそ{0}さん", user.Name) : "ようこそ";
quotaText.Text = string.Format("{0}%使用中({1} bytes中{2} 使用可能)",
((int)(quota.AvailableBytes / quota.QuotaBytes) * 100),
quota.QuotaBytes, quota.AvailableBytes);
}
@tanaka-takayoshi
tanaka-takayoshi / StringExtention.cs
Created May 20, 2013 17:25
C# で指定したエンコードで指定したバイト数"以下"に安全に文字列を切り詰めるメソッド。 1文字を2バイト以上で表現する場合、その途中のバイトで切り詰めずにより短くなるようにする。
public static class StringExtention
{
public static string LeftB(this string s, Encoding encoding, int maxByteCount)
{
var bytes = encoding.GetBytes(s);
if (bytes.Length <= maxByteCount) return s;
var result = s.Substring(0,
encoding.GetString(bytes, 0, maxByteCount).Length);
static Task RunProcess(ProcessStartInfo psi)
{
var tcs = new TaskCompletionSource<bool>();
var process = new Process
{
StartInfo = psi,
EnableRaisingEvents = true
};
process.ErrorDataReceived += (s, e) => tcs.SetException(new Exception("err"));
process.Exited += (sender, args) => tcs.SetResult(true);
@tanaka-takayoshi
tanaka-takayoshi / install_monit.sh
Created August 13, 2013 10:47
install monit 5.5 on Amazon Linux
yum -y install flex bison openssl-devel rpm-build gcc pam-devel
wget http://mmonit.com/monit/dist/monit-5.5.tar.gz
tar zxvf monit-5.5.tar.gz
mkdir -p /root/rpmbuild/SOURCES
cp monit-5.5.tar.gz /root/rpmbuild/SOURCES/monit-5.5.tar.gz
cd monit-5.5
rpmbuild -bb --clean contrib/packages/redhat/monit.spec
rpm -ivh /root/rpmbuild/RPMS/x86_64/monit-5.5-1.x86_64.rpm