2015의 게시물 표시

EJBCA Web Service

import java.net.MalformedURLException; import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import javax.xml.namespace.QName; import org.ejbca.core.protocol.ws.client.gen.EjbcaWS; import org.ejbca.core.protocol.ws.client.gen.EjbcaWSService; public class Program { public static void main(String[] args) { EjbcaWS ejbcaws = null;  // A single instance is enough //CryptoProviderTools.installBCProvider(); // TODO Auto-generated method stub         System.setProperty ("javax.net.ssl.trustStore", "c:\\temp\\truststore.jks");         System.setProperty ("javax.net.ssl.trustStorePassword", "changeit"); ...

P12 <--> JKS

keytool -importkeystore -srckeystore superadmin.p12 -srcstoretype PKCS12 -deststoretype JKS -destkeystore superadmin.jks http://blog.ejbca.org/2008/02/converting-keystores-between-jks-and.html

Key generation

package cccc; import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; import java.security.Security; //import java.util.Base64; import org.apache.commons.codec.binary.Base64; import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; import org.bouncycastle.crypto.util.PrivateKeyInfoFactory; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.math.ec.ECCurve; //import ; import org.bouncycastle.util.encoders.Hex; import org.bouncycastle.jce.spec.ECParameterSpec; public class vvv { public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { Security.addProvider(new BouncyC...

What are Keycloak's OAuth2 / OpenID Connect endpoints?

http://stackoverflow.com/questions/28658735/what-are-keycloaks-oauth2-openid-connect-endpoints

.NET 비동기 프로그래밍

http://blogs.msdn.com/b/ pfxteam/ https://msdn.microsoft.com/en- us/magazine/jj991977.aspx

decimal vs float and double

http://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net

Type-safe-enum pattern equivalent to java's enum

http://stackoverflow.com/questions/424366/c-sharp-string-enums

The lifecycle of an Android Activity

이미지

Writing to the Eclipse console

먼저 plugin.xml 에서 디펜던시를 org.eclipse.ui.console을 추가하고 나서 private MessageConsole findConsole(String name) {      ConsolePlugin plugin = ConsolePlugin.getDefault();      IConsoleManager conMan = plugin.getConsoleManager();      IConsole[] existing = conMan.getConsoles();      for (int i = 0; i < existing.length; i++)         if (name.equals(existing[i].getName()))            return (MessageConsole) existing[i];      //no console found, so create a new one      MessageConsole myConsole = new MessageConsole(name, null);      conMan.addConsoles(new IConsole[]{myConsole});      return myConsole;   } 메서드를 추가. 이름은 "Console" 혹은 "System output" 을 입력해서 아래처럼 사용 MessageConsole myConsole = findConsole("System Output");   MessageConsoleStream out = myConsole.newMessageStream(); ...

Reading resources from a Eclipse plugin

Bundle bundle = Platform.getBundle( "de.vogella.example.readfile" ); URL fileURL = bundle.getEntry( "files/test.txt" ); try {     URL resolvedFileURL = FileLocator.toFileURL(fileURL); URI resolvedURI = new URI(resolvedFileURL.getProtocol(), resolvedFileURL.getPath(), null); File file = new File(resolvedURI);    //file = new File(FileLocator.resolve(fileURL).toURI());    boolean a = file.exists();    MessageDialog.openInformation( window.getShell(), "Sample2", file.toPath().toAbsolutePath().toString() + ", " + String.valueOf(a));    System.out.println(file.toPath().toAbsolutePath().toString()); } catch (URISyntaxException e1) {      e1.printStackTrace(); } catch (IOException e1) {      e1.printStackTrace(); } http://blog.vogella.com/2010/07/06/reading-resources-from-plugin/

Read registry on 64bit machine

var hlkm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); var key = hlkm.OpenSubKey(@"SOFTWARE\JavaSoft\Java Plug-in\11.31.2"); var java = key.GetValue("JavaHome"); http://stackoverflow.com/questions/13728491/opensubkey-returns-null-for-a-registry-key-that-i-can-see-in-regedit-exe

To Capture Console's output

using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; using System.Windows; namespace ConsoleWPF {     /// <summary>     ///     Interaction logic for MainWindow.xaml     /// </summary>     public partial class MainWindow : Window     {         public MainWindow()         {             InitializeComponent();         }         private void ButtonBase_OnClick(object sender, RoutedEventArgs e)         {             var p = new Process();             Task.Factory.StartNew(() =>             {                 var pInfo = new ProcessStartInfo("cmd.exe", "/c dir")             ...

WPF 레이아웃

이미지
WPF layout system.

WPF UI debugging tool

https://snoopwpf.codeplex.com/ WPF visualizer

With ContextMenu, Databinding is set after being shown.

http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/

ScrillViewer, Canvas and Image

<Window x:Class="WpfViewBox.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:wpfViewBox="clr-namespace:WpfViewBox"         Title="MainWindow" Height="350" Width="525">     <Grid ShowGridLines="True">         <Grid.RowDefinitions>             <RowDefinition Height="Auto" />             <RowDefinition Height="*" />         </Grid.RowDefinitions>         <StackPanel Grid.Row="0">             <Button Name="Button1" Content="Click" Click="Button1_OnClick" HorizontalAlignment="Left" />         </StackPanel>         <ScrollViewer Grid.Row...

Performance Analyzing

이미지
Tool Description Visual Studio Performance Analysis Use to analyze the CPU usage of your .NET Framework apps that will be deployed to computers that are running the Windows operating system. This tool is available from the  Debug  menu in Visual Studio after you open a project. For more information, see  Analyzing Application Performance by Using Profiling Tools .   Note Use Windows Phone Application Analysis (see next row) when targeting Windows Phone. Windows Phone Application Analysis Use to analyze the CPU and memory, network data transfer rate, app responsiveness, and battery consumption in your Windows Phone apps. This tool is available from the  Debug  menu for a Windows Phone project in Visual Studio after you install the  Windows Phone SDK . For more information, see  App profiling for Windows Phone . PerfView Use to identify CPU and memory-related performance issues. This tool uses event tracing for Windo...

Very simple state monitor

소스

Enum and Attribute

public static IEnumerable<T1> FilterEnumerables<T1, T2>(Predicate<T2> predicate) where T1 : struct, IConvertible //Enum where T2 : Attribute //Attribute { return typeof (T1) .GetFields() .Where(f => f.GetCustomAttributes(typeof (T2)).Any() && predicate(f.GetCustomAttribute<t2>())) .Select(f => (T1) Enum.Parse(typeof (T1), f.Name)); }

Stop console process using Ctrl+C.

http://stackoverflow.com/questions/813086/can-i-send-a-ctrl-c-sigint-to-an-application-on-windows https://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx private void Button1_OnClick(object sender, RoutedEventArgs e) { var file = new FileInfo(@"C:\temp\video.mp4"); if (file.Exists) { file.Delete(); } ct = new CancellationTokenSource(); Task.Factory.StartNew(() => { var pInfo = new ProcessStartInfo("cmd.exe", string.Format("/c {0} \"{1}\"", new object[] {"adb.bat", file.Name})); pInfo.CreateNoWindow = true; pInfo.UseShellExecute = false; pInfo.RedirectStandardError = true; pInfo.RedirectStandardOutput = true; pInfo.RedirectStandardInput = true; var p = Process.Start(pInfo); ...

adb command for dump and capture

echo %time% adb shell uiautomator dump /data/local/tmp/dump.xml adb pull /data/local/tmp/dump.xml %1 adb shell screencap /data/local/tmp/dump.raw adb pull /data/local/tmp/dump.raw %2 echo %time%

Binary/Soap formatter code

public static void SerializeToBin(this object objectGraph, FileInfo target) { if (target.Exists) { target.Delete(); } using (var fs = target.Create()) { var bs = new BinaryFormatter(); bs.Serialize(fs, objectGraph); } } public static T DeserializeFromBin (this FileInfo source) { if (!source.Exists) { return default(T); } using (var fs = source.OpenRead()) { var bs = new BinaryFormatter(); return (T)bs.Deserialize(fs); } } public static void SerializeToSoap(this object objectGraph, FileInfo target) { if (target.Exists) { target.Delete(); } using (var fs = target.Create()) { var bs = new SoapForma...

Alternative to IValueConvert, QuickConverter

https://quickconverter.codeplex.com/ Quick Setup Steps Add the assembly reference to your project. This can also easily be done using  the NuGet package . Add the namespaces to Quick Converter that it will need to know about (before any xaml that uses it is loaded). e.g. In your WPF application's App.xaml.cs file: public   partial   class   App  :  Application { public  App() :  base () { // Setup Quick Converter. // Add the System namespace so we can use primitive types (i.e. int, etc.). QuickConverter. EquationTokenizer .AddNamespace( typeof ( object )); // Add the System.Windows namespace so we can use Visibility.Collapsed, etc. QuickConverter. EquationTokenizer .AddNamespace( typeof (System.Windows. Visibility )); } } Add the Quick Converter namespace to your xaml files so you can ref...

롤리팝에서 UiAutomator Viewer실행 결과에서 한글 깨짐.

https://code.google.com/p/android/issues/detail?id=115418

Find and Replace

http://sourceforge.net/projects/findandreplace/

java read file line by line using bufferedreader

http://www.programcreek.com/2011/03/java-read-a-file-line-by-line-code-example/

How to check whether excel file is already opened with C#

Excel.Application oExcelApp; using Excel = Microsoft.Office.Interop.Excel; .... .... Excel.Workbook xlwkbook = (Excel.Workbook)System.Runtime.InteropServices.Marshal.BindToMoniker(@"C:\temp\book1.xlsx"); //True : already opened by human. False : not opened by human bool isOpened = xlwkbook.Application.Windows["book1.xlsx"].Visible; Trace.WriteLine(isVis);

Clean up COM object

http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects/159419#159419

How to use Visual C# to automate a running instance of an Office program

http://support2.microsoft.com/default.aspx?scid=kb;EN-US;316126             Excel.Application oExcelApp;             Excel.Workbook xlwkbook = (Excel.Workbook)System.Runtime.InteropServices.Marshal.BindToMoniker(@"C:\temp\booke1.xlsx");             Excel.Worksheet s = xlwkbook.ActiveSheet;             Range x = s.Cells[2, 1];             x.Value = "bbcccccbbbb";             MessageBox.Show(xlwkbook.Path);             //xlwkbook.Save();             //Release the reference.             oExcelApp = null;

Comparison Soap/BinaryFormatter to XmlSerialzer

이미지
http://www.dotneat.net/2009/03/22/NETSerializationUsingBinaryFormaterSoapFormatterAndXmlSerializer.aspx

Window Debugging

Windows Driver Kit(KDK) Download Download Windows Symbol Packages

Android Studio 프록시 네트웍 환경에서 사용하기.

프록시 세팅이 안 되어 있으니 처음에 실행하면 연결 안 됨. bin 폴더의 idea.properties 파일의 끝에 다음을 추가. disable.android.first.run=true 참고