This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, " "); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <termios.h> | |
struct termios term; | |
tcgetattr(STDIN_FILENO, &term); | |
term.c_oflag &= ~OPOST; | |
tcsetattr(STDIN_FILENO, TCSANOW, &term); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let it = vec![1, 2, 3, 4].into_iter().inspect(|x| println!("value is {}", x)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rgba := [r, g, b, a, r, g, b, a, ...] | |
for alpha in rgba.skip(3).step_by(4) { | |
do_something_with_alpha(alpha); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<_>>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@functools.cache | |
def fibonacci(n): | |
if n == 0 or n == 1: | |
return n | |
return fibonacci(n - 1) + fibonacci(n - 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_heavy_function.cache_info() # CacheInfo(hits=20, misses=12, maxsize=1000, currsize=12) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
port functools | |
import itertools | |
import math | |
import sys | |
def is_pentagonal(n): | |
return math.sqrt(24 * n + 1) % 6 == 5 |
NewerOlder