Skip to content

Instantly share code, notes, and snippets.

@imxiaohui
imxiaohui / .clang-format
Created October 9, 2018 12:06
dot_clang-format
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
@imxiaohui
imxiaohui / playground.rs
Created May 26, 2018 01:50 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::collections::HashSet;
fn files_name(names: Vec<String>) -> Vec<String> {
let mut map = HashSet::new();
let mut result = vec![];
for name in &names {
if !map.contains(name) {
map.insert(name.clone());
result.push(name.clone());
@imxiaohui
imxiaohui / playground.rs
Created May 12, 2018 14:03 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn is_mac48_address(input_string: &str) -> bool {
let mut n = 0usize;
for chunk in input_string.split('-') {
let mut count = 0usize;
for ch in chunk.chars() {
if !ch.is_digit(16) {
return false;
}
count += 1;
}
@imxiaohui
imxiaohui / build_palindrome.rs
Last active May 12, 2018 03:57 — forked from rust-play/playground.rs
Codefights buildPalindrome #rust #codefights
fn build_palindrome(st: String) -> String {
let len = st.len();
let mut i = 0;
let mut j = len - 1;
let chars = st.chars().collect::<Vec<_>>();
while i < j {
j = if chars[i] == chars[j] { j - 1 } else { len - 1 };
i += 1;
}
@imxiaohui
imxiaohui / playground.rs
Last active May 10, 2018 07:48 — forked from rust-play/playground.rs
Code shared from the Rust Playground #rust
fn strings_rearrangement(inputs: Vec<String>) -> bool {
let mut marks = vec![false; inputs.len()];
let found = backtrack(&inputs, &mut marks, "", 0);
found
}
fn backtrack(inputs: &[String], marks: &mut [bool], last: &str, pos: usize) -> bool {
if pos == marks.len() {
return true;
}
@imxiaohui
imxiaohui / hashset_union.rs
Last active May 10, 2018 06:09 — forked from rust-play/playground.rs
how to update a hashset with intersection or union
#![allow(unused)]
fn main() {
use std::collections::HashSet;
let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
// Can be seen as `a - b`.
for x in a.difference(&b) {
println!("{}", x); // Print 1
}
@imxiaohui
imxiaohui / LICENCE SUBLIME TEXT
Created December 10, 2017 08:35
Sublime Text 3 Serial key build is 3143
## Sublime Text 3 Serial key build is 3103
—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04
B085E65E 2F5F5360 8489D422 FB8FC1AA
@imxiaohui
imxiaohui / io.cpp
Created September 13, 2017 10:27
Fast I/O in C/C++
/*
grab the whole line
char a[100];
cin.getline(a,100);
scanf("%[^\n]",a);
gets(a);
*/
inline void fastRead_int(int *a)
{
@imxiaohui
imxiaohui / file_io.rs
Created May 21, 2017 13:34
rust, file, io, read, write
// open.rs
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
fn main() {
// Create a path to the desired file
let path = Path::new("hello.txt");
let display = path.display();
@imxiaohui
imxiaohui / 1_simple.go
Created March 8, 2017 07:23 — forked from sosedoff/1_simple.go
Golang Custom Struct Tags Example
package main
import (
"fmt"
"reflect"
)
// Name of the struct tag used in examples
const tagName = "validate"