Skip to content

Instantly share code, notes, and snippets.

void display_progress_bar(int progress) {
static const int PROGRESS_BAR_LENGTH = 20;
int filled = progress * PROGRESS_BAR_LENGTH / 100;
fprintf(stderr, "\r[");
for (int i = 0; i < filled; i += 1) {
fprintf(stderr, "#");
}
for (int i = filled; i < PROGRESS_BAR_LENGTH; i += 1) {
fprintf(stderr, " ");
#include <termios.h>
#include <unistd.h>
int main() {
struct termios term;
if (tcgetattr(STDIN_FILENO, &term) < 0) {
printf("can't get tty settings\n");
return -1;
}
#include <termios.h>
struct termios term;
tcgetattr(STDIN_FILENO, &term);
term.c_oflag &= ~OPOST;
tcsetattr(STDIN_FILENO, TCSANOW, &term);
let it = vec![1, 2, 3, 4].into_iter().inspect(|x| println!("value is {}", x));
// rgba := [r, g, b, a, r, g, b, a, ...]
for alpha in rgba.skip(3).step_by(4) {
do_something_with_alpha(alpha);
}
@sgkim126
sgkim126 / map.rs
Created August 1, 2021 14:53
map example
let old_vec = vec![1, 2, 3, 4];
let original = old_vec.into_iter();
let doubled = original.map(|x| x * 2);
assert_eq!(vec![2, 4, 6, 8], doubled.collect::<Vec<_>>());
@functools.cache
def fibonacci(n):
if n == 0 or n == 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
_heavy_function.cache_info() # CacheInfo(hits=20, misses=12, maxsize=1000, currsize=12)
def heavy_function(set_arg, lst_arg):
return dict(_heavy_function(frozenset(set_args), tuple(lst_arg)).items())
@functools.lru_cache(maxsize=1000)
def _heavy_function(frozenset_arg, tuple_arg):
return result_dictionary()
#!/usr/bin/env python3
port functools
import itertools
import math
import sys
def is_pentagonal(n):
return math.sqrt(24 * n + 1) % 6 == 5