Instantly share code, notes, and snippets.

# yuki.Nfairjm

• Sort options
Last active Dec 22, 2019
View 1. Two Sum.rs
 /// https://leetcode.com/problems/two-sum/ impl Solution { fn two_sum(nums: Vec, target: i32) -> Vec { let mut nums2 = nums.clone(); nums2.sort(); let mut begin = 0; let mut end = nums.len() - 1; while begin < end { let r = nums2[begin] + nums2[end]; if r == target {
Last active Jun 6, 2019
store some snippets
View elixir_snippet.exs
 camelcase = fn a -> Regex.replace(~r/_([a-z]+)/,a, fn _,<> -> String.upcase(<>) <> b end) end upcaseFirst = fn "" -> "" <> -> String.upcase(<>) <> b end # md5 see https://gist.github.com/10nin/5713366 def md5(data) do Base.encode16(:erlang.md5(data), case: :lower)
Created May 29, 2018
create sql to java fields
View create_sql_to_java.py
 import re code = """ `name` varchar(10) DEFAULT NULL', `age` int NOT NULL DEFAULT '' """ def parse_field_name(s): return re.sub(r"_(.)", lambda x: x.group(1).upper(), s.replace("`","")) def parse_field_type(t):
Created Nov 7, 2017
spring mvc imageIO add text to image
View PicGenController.java
 package com.cc.imageio.controller; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File;
Created Oct 23, 2016
F# get attachment filename by httpclient
View filename.fs
 open System.Net.Http open System.Net.Mime open System.Text ///get fileName by ContentDisposition or random file name if null let getFileName (msg: HttpResponseMessage) = let value = Option.ofObj msg.Content.Headers.ContentDisposition let result = value |> Option.map (fun e -> e.FileName)
Created Sep 14, 2016
FSharp Dapper with FSharp.Interop.Dynamic
View mysql.fsx
 open MySql.Data.MySqlClient open FSharp.Interop.Dynamic open Dapper open System open System.Dynamic type GList<'a> = System.Collections.Generic.List<'a> type Ask() = member val AskId = 0 with get,set
Created Feb 19, 2016
get fore ground window
View GetForegroundWindow.cs
 /// /// by fairjm. /// 2016/02/19 /// class Program { [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")]
Last active Dec 7, 2015
XStream handle map with key value pair with CDATA embeded
View XmlMapUtil.java
 import java.io.Writer; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.converters.Converter;
Created Sep 15, 2015
fsharp-prime
View prime.fs
 let prime () = let infinity = Seq.initInfinite (fun i -> i + 1) |> Seq.filter (fun n -> n >= 2) |> Seq.cache let rec inner (nums: seq) = seq { let i = Seq.item 0 nums yield i let next = nums |> Seq.filter (fun n -> n % i <> 0) |> inner yield! next }
Last active Sep 8, 2015
cmd wrapper
View wrapper.fsx
 open System open System.Text open System.IO open System.Diagnostics let newProcess = new Process() newProcess.StartInfo.FileName <- "cmd.exe" newProcess.StartInfo.CreateNoWindow <- true newProcess.StartInfo.UseShellExecute <- false newProcess.StartInfo.RedirectStandardInput <- true
You can’t perform that action at this time.