Skip to content

Instantly share code, notes, and snippets.

#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
int
parse_signed(const char src[static 1], intmax_t min, intmax_t max,
intmax_t dest[static 1], char **endptr) {
int sign;
intmax_t value;
# sample input: 10-1000,15-350,50-1500,2100,1700-1800,45,40,145,2-1300
set -o pipefail
tr , '\n' | sort -n | awk '
BEGIN {
FS = OFS = "-"
}
NF < 1 || NF > 2 || (NF == 2 && $1 > $2) {
print "bad input: " $0 | "cat >&2"
exit 1
}
#include <stdio.h>
#include <ctype.h>
#include <strings.h>
static int
is_palindromic(const char *str, size_t n) {
size_t i, j;
if (n == 0)
return 1;
# Takes an IPv6 address as argument
# and encodes it as described in RFC1924.
export LC_ALL=C
export POSIXLY_CORRECT=1
unset BC_ENV_ARGS
unset BC_LINE_LENGTH
d0='0' d10='A' d20='K' d30='U' d40='e' d50='o' d60='y' d70='+' d80='`'
d1='1' d11='B' d21='L' d31='V' d41='f' d51='p' d61='z' d71='-' d81='{'
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define WIDTH 64
#define HEIGHT 64
#define AREA (WIDTH * HEIGHT)
#define WHITE 255
#define BLACK 0
wrapper=
status=0
badsrc() {
printf 'skipping %s\n' "$src" >&2
status=1
}
randstr() {
tr -cd '[:alnum:]' </dev/urandom | head -c 10
#include <assert.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct node *node;
typedef struct node *leaf;
typedef struct {
int last;
@oguz-ismail
oguz-ismail / nowebp
Last active November 25, 2022 11:43
convert all WEBP to PNG/JPG
# nowebp - find and convert WEBP images
#
# Usage: nowebp [DIR]
#
# nowebp searches the directory hierarchy starting from DIR (current
# directory if absent) for images in WEBP format, and converts each
# image it finds to PNG or JPG, depending on whether it is compressed
# losslessly or contains transparent pixels, or neither, respectively.
export LC_ALL=C
@oguz-ismail
oguz-ismail / rev.c
Last active November 19, 2022 17:23
reverse string using libunistring routines
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <uniconv.h>
#include <unigbrk.h>
#include <unistr.h>
int
reverse(uint8_t *str) {
size_t len;
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef STACK_SIZE_MAX
#define STACK_SIZE_MAX 1000
#endif
double stack[STACK_SIZE_MAX];