Skip to content

Instantly share code, notes, and snippets.

@foresta
foresta / cargo.toml
Created March 5, 2023 10:37
File Download sample
[package]
name = "file-downloader"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11", features=["stream"]}
tokio = { version = "1.26.0", features=["fs", "full"]}
@foresta
foresta / progress_bar.sh
Created October 23, 2022 11:07
bash progress bar
#!/bin/bash
progress_bar() {
current=$1
total=$2
progress=$(($current * 100 / ${total}))
bar="$(yes '#' | head -n ${progress} | tr -d '\n')"
if [ -z "$bar" ]; then
@foresta
foresta / ParallelDispatchQueue.swift
Last active September 9, 2019 04:56
Async Request Sample
typealias AsyncCallback = () -> Void
func getFriends() {
let dispatchGroup = DispatchGroup()
let dispatchQueue = DispatchQueue(label: "twitterAPIQueue", attributes: .concurrent)
// 非同期のGroupとQueueに書くメソッドを割り当てる
dispatch(group: dispatchGroup, queue: dispatchQueue, method: getFollows)
dispatch(group: dispatchGroup, queue: dispatchQueue, method: getFollowers)
@foresta
foresta / ParallelCallback.swift
Last active September 9, 2019 05:02
Async Request Sample
func getFriends() {
let numberOfParallel: Int = 2
var completionCount: Int = 0
// 呼ばれるたびに 1ずつ足していって並列実行数を超えたら何かのメソッドを呼ぶ
completion = []() {
completionCount += 1
if (numberOfParallel >= comletionCount) {
// 突合する処理など
doSomethingAfterFetchFriends()