Skip to content

Instantly share code, notes, and snippets.

yuki.N fairjm

Block or report user

Report or block fairjm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fairjm
fairjm / 1. Two Sum.rs
Last active Dec 22, 2019
my_bad_solutions
View 1. Two Sum.rs
/// https://leetcode.com/problems/two-sum/
impl Solution {
fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
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 {
@fairjm
fairjm / elixir_snippet.exs
Last active Jun 6, 2019
store some snippets
View elixir_snippet.exs
camelcase = fn a -> Regex.replace(~r/_([a-z]+)/,a, fn _,<<w::utf8, b::binary>> -> String.upcase(<<w>>) <> b end) end
upcaseFirst = fn
"" -> ""
<<a::utf8, b::binary>> -> String.upcase(<<a>>) <> b
end
# md5 see https://gist.github.com/10nin/5713366
def md5(data) do
Base.encode16(:erlang.md5(data), case: :lower)
@fairjm
fairjm / create_sql_to_java.py
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):
@fairjm
fairjm / PicGenController.java
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;
@fairjm
fairjm / filename.fs
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)
@fairjm
fairjm / mysql.fsx
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
@fairjm
fairjm / GetForegroundWindow.cs
Created Feb 19, 2016
get fore ground window
View GetForegroundWindow.cs
/// <summary>
/// by fairjm.
/// 2016/02/19
/// </summary>
class Program
{
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
@fairjm
fairjm / XmlMapUtil.java
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;
@fairjm
fairjm / prime.fs
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<int>) = seq {
let i = Seq.item 0 nums
yield i
let next = nums |> Seq.filter (fun n -> n % i <> 0) |> inner
yield! next
}
@fairjm
fairjm / wrapper.fsx
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.