Skip to content

Instantly share code, notes, and snippets.

View qianyan's full-sized avatar

Yan Qian qianyan

View GitHub Profile
@qianyan
qianyan / enviroments.gradle
Created April 22, 2020 15:33
Replace the placeholders of config file in yaml with environment variables in gradle files
import groovy.text.SimpleTemplateEngine
import org.yaml.snakeyaml.Yaml
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
pub mod two_sum_bst {
use std::rc::Rc;
use std::cell::RefCell;
#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
pub val: i32,
pub left: Option<Rc<RefCell<TreeNode>>>,
pub right: Option<Rc<RefCell<TreeNode>>>,
}
@qianyan
qianyan / zsh svn prompt.sh
Created January 2, 2018 09:51
svn prompt support for zsh
local svn_info='$(svn_prompt_info)'
local color_svn_info=%{$reset_color%}${svn_info}%{$reset_color%}
if [[ $PROMPT != *${svn_info}* ]]
then
PROMPT=$PROMPT${color_svn_info}
fi
ZSH_THEME_SVN_PROMPT_PREFIX="%{$fg_bold[blue]%}svn:("
ZSH_THEME_SVN_PROMPT_SUFFIX="%{$fg_bold[blue]%})"
ZSH_THEME_SVN_PROMPT_DIRTY="%{$fg[red]%} ✘ %{$reset_color%}"
@qianyan
qianyan / view flatten APIs from swagger
Created October 13, 2017 03:00
view flatten APIs with Node.js
const _ = require('lodash')
const fs = require('fs')
var Lazy = require('lazy')
const swaggerDoc = "your.yaml"
const prefixOfURI = "/"
new Lazy(fs.createReadStream(swaggerDoc))
.lines
.map( l => l.toString().trim().slice(0, -1) ) // delete the last char ':'
.filter(line => line.startsWith(prefixOfURI) || ['get', 'post', 'put', 'patch', 'delete'].includes(line) )
@qianyan
qianyan / java8 - frequency and unique?
Last active October 13, 2017 03:02
implement frequency and unique? in java8
// frequency
Stream.of("a", "a", "b", "c").collect(toMap(identity(), a -> 1, (a, b) -> a + b));
Stream.of("a", "a", "b", "c").collect(groupingBy(identity(), counting()));
Stream.of("a", "a", "b", "c").collect(groupingBy(identity(), summingInt(v -> 1)));
Stream.of("a", "a", "b", "c").collect(groupingBy(identity(), mapping(identity(), summingInt(v -> 1))));
-> {a=2, b=1, c=1}
// unique?
frequency().values().stream().anyMatch(c -> c > 1);

Keybase proof

I hereby claim:

  • I am qianyan on github.
  • I am lambeta (https://keybase.io/lambeta) on keybase.
  • I have a public key whose fingerprint is 960A DEDD EBAA BFBC E67E E66A B845 5D1D 3C50 30FF

To claim this, I am signing this object:

SourceTreeSetup_1.6.20.exe /extract
msiexec /a SourceTreeSetup_1.6.20.msi /qb TARGETDIR="%temp%\SourceTree"
xcopy "%temp%\SourceTree" "C:\Dev\sourceTree" /S
rmdir "%temp%\SourceTree" /S
@qianyan
qianyan / browse-git.sh
Last active August 29, 2015 14:27
Open chrome to browse your online project when you are under git controlled directory.
# open with chrome
open -a 'Google Chrome' `cat .git/config | awk '/url/{print $3}'`
# open with default browser
open `cat .git/config | awk '/url/{print $3}'`
# alias
alias gon="cat .git/config | awk '/url/{print \$3}' | xargs open"