Skip to content

Instantly share code, notes, and snippets.

View leikahing's full-sized avatar
🧧
Chaining the blocks

William Lee leikahing

🧧
Chaining the blocks
View GitHub Profile
fn main() {
let p : Option<&'W String>;
{
let mut map = Map::new();
// fully qualified paths which give explicit lifetime notation
Map::insert(&'X mut map, 'a', format!("alpha"));
p = Map::get(&'Y map, &'Z 'a')
}
println!("key for 'a' is {:?}", p);
@leikahing
leikahing / group-as-subhash.ps1
Last active May 30, 2017 15:26
Group list-of-objects in powershell
$oracleList =
@([pscustomobject]@{odata="OraclePrinter1"; uuid="100"},
[pscustomobject]@{odata="OraclePrinter2"; uuid="200"},
[pscustomobject]@{odata="OraclePrinter3"; uuid="300"})
$mysqlList =
@([pscustomobject]@{sqldata="MySqlPrinter1"; uuid="100"},
[pscustomobject]@{sqldata="MySqlPrinter2"; uuid="200"},
[pscustomobject]@{sqldata="MySqlPrinter3"; uuid="300"})
@leikahing
leikahing / find_improper_whisper.sh
Created February 28, 2017 23:33
Scratch whisper
wspfiles=$(find $1 -name "lower.wsp" -o -name "upper.wsp" -o -name "p95.wsp" -o -name "p99.wsp" -o -name "p50.wsp" -o -name "count.wsp" -o -name "mean.wsp" -o -name "stdev.wsp" -o -name "sum.wsp" -o -name "rate.wsp" -o -name "sum_sq.wsp" -o -name "median.wsp" -o -name "sample_rate.wsp")
for f in $wspfiles; do
name=$(basename "$f")
method=$(whisper-info.py $f aggregationMethod)
status=""
case "$name" in
lower.wsp)
if [[ "$method" == "min" ]]; then
node("ECS/node") {
deleteDir()
checkout scm
sh "node scripts/yarn-0.18.1.js install --mutex network"
}
@leikahing
leikahing / proxy.rs
Last active January 30, 2017 19:16
Rust proxy thingy
let proxy_stream = stream.map(|(addr, msg)| {
let s = String::from_utf8_lossy(&msg);
// for each line in s
// split on first dot
// filter out anything that's not a valid token
// get the second tuple element out
// collect back into a vector of strings
let (valid, invalid): (Vec<(&str, &str)>, Vec<(&str, &str)>) = s.lines().map( |l| split_once(&l) ).partition( |&p| valid_tokens.contains_key(&*p.0) );
let valid_stat_bytes : Vec<u8> = valid.iter().map( |t| t.1 ).collect::<Vec<&str>>().join("\n").into_bytes();
@leikahing
leikahing / json-to-hash.ps1
Created December 14, 2016 16:21
JSON to Hashtable
$headers = @{}
$jsoncontent = Get-Content -Raw -path jsonfile.json | ConvertFrom-Json
$jsoncontent.psobject.properties | foreach { $headers[$_.Name] = $_.Value }
@leikahing
leikahing / gist:90917603a19aec2128dc0d28b4cf1bd3
Created December 8, 2016 19:22
macos + cake.build + msbuild + dotnetcore
birryree >> ~ >> code >> Cabinet.Next >> ./build.sh
Feeds used:
/Users/birryree/.local/share/NuGet/Cache
/Users/birryree/.nuget/packages/
https://www.myget.org/f/dotnet-core
https://www.nuget.org/api/v2/
All packages listed in /Users/birryree/code/uploads/Cabinet.Next/tools/packages.config are already installed.
Analyzing build script...
Processing build script...
@leikahing
leikahing / task.json
Last active November 11, 2016 21:09
Linked container task definition ECS
{
"requiresAttributes": [
{
"value": null,
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"value": null,
"name": "com.amazonaws.ecs.capability.task-iam-role"
}
@leikahing
leikahing / semicolons.txt
Created September 26, 2016 19:12
Whitespace vs. Semicolons
> clang++ -ftime-report bigx.cxx
===-------------------------------------------------------------------------===
Miscellaneous Ungrouped Timers
===-------------------------------------------------------------------------===
---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
0.0097 ( 57.7%) 0.0013 ( 42.3%) 0.0110 ( 55.4%) 0.0111 ( 55.6%) LLVM IR Generation Time
0.0071 ( 42.3%) 0.0017 ( 57.7%) 0.0089 ( 44.6%) 0.0089 ( 44.4%) Code Generation Time
0.0169 (100.0%) 0.0030 (100.0%) 0.0199 (100.0%) 0.0200 (100.0%) Total
@leikahing
leikahing / run_nvm.sh
Created August 6, 2016 21:24
Hack to run nvm from script
#!/bin/bash
source $NVM_DIR/nvm.sh
nvm exec 5.9.1 node --version