Skip to content

Instantly share code, notes, and snippets.

Avatar

Le Dinh Cuong cuongld2

View GitHub Profile
View example_setup_teardown.rs
use std::panic;
use rstest::*;
fn setup(){
println!("setup 111");
}
fn teardown(){
println!("teardown 2222");
View example_rstest.rs
use rstest::*;
use std::sync::Once;
static INIT: Once = Once::new();
#[fixture]
pub fn setup() -> () {
INIT.call_once(|| {
println!("Hello, world!");
// initialization code here
@cuongld2
cuongld2 / main.rs
Created Jul 22, 2021
Comparison between .len() and .chars().count()
View main.rs
fn main() {
let s1=String::from("ラウトは難しいです!");
let len = calculate_length(&s1);
let chars = calculate_characters(&s1);
println!("The length of {:?} is {:?}.",s1,len);
println!("The number of chars of {:?} is {:?}.",s1,chars);
View pipe.rs
let input = Command::new("yes")
.stdout(Stdio::piped())
.spawn();
let _ = Command::new("gen3-client")
.arg("download-single")
.args(&["--profile=tysud456", "--guid=c254e7d9-bd10-4f8b-803f-5388de3eba9c","--filename-format=original","--rename"])
.stdin(input.ok().unwrap().stdout.unwrap())
.output().ok()
View unmarshal.go
var geneCSV []string
geneCSV = append(geneCSV, geneBackup, strconv.Itoa(geneXML.IdList[0]))
data = append(data, geneCSV)
View Symbolsearchxml.go
type SymbolSearchXml struct {
XMLName xml.Name `xml:"eSearchResult"`
Count int `xml:"Count"`
RetMax int `xml:"RetMax"`
RetStart int `xml:"RetStart"`
IdList []int `xml:"IdList>Id"`
TranslationSet string `xml:"TranslationSet"`
TranslationStack TranslationStackXml `xml:"TranslationStack"`
QueryTranslation string `xml:"QueryTranslation"`
}
@cuongld2
cuongld2 / variant_id.go
Created Jun 5, 2021
Retrieve variant_id from complex json
View variant_id.go
var mapResp map[string]interface{}
if err := json.NewDecoder(res.Body).Decode(&mapResp); err == nil {
// fmt.Println(`&mapResp:`, &mapResp, "\n")
// fmt.Println(`mapResp["hits"]:`, mapResp["hits"])
for _, value := range mapResp["hits"].(map[string]interface{}) {
if reflect.TypeOf(value).Kind() != reflect.Float64 {
for _, each := range value.([]interface{}) {
@cuongld2
cuongld2 / quick_sort.jl
Created May 22, 2021
quick sort implementation in julia
View quick_sort.jl
function quick_sort(list)
if length(list)<2
return list
end
pivot = list[1]
greater = []
lesser = []
for i = 2:length(list)
if pivot <= list[i]
append!(greater,list[i])
@cuongld2
cuongld2 / binary_search.jl
Created May 21, 2021
binary search using recursion in julia language
View binary_search.jl
k=0
g=0
t=0
function binary_search(list,item,len_list)
global k
global g
global t
if list==[]
return 0
end
@cuongld2
cuongld2 / maximum.jl
Created May 20, 2021
Find maxium number in a list - julia
View maximum.jl
function find_maximum(array)
global maximum
if length(array)==0
return maximum
end
if maximum<last(array)
maximum=last(array)
end
println(array)