Skip to content

Instantly share code, notes, and snippets.

View ivanria's full-sized avatar

Ivan ivanria

  • Russia, Moscow
View GitHub Profile
@ivanria
ivanria / bits.py
Created April 14, 2026 12:44
convert digit to binary view
#!/usr/bin/env python3
import sys
def convert_to_bin():
if len(sys.argv) < 3:
print("Использование: ./bins.py <кол-во_байт> <число>")
print("Пример: ./bins.py 1 255")
return
try:
@ivanria
ivanria / task.c
Last active April 11, 2026 22:16
KNX parse
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#define DEBUG
#ifdef DEBUG
#define DEBUG_MODE 1
@ivanria
ivanria / timers.c
Created December 1, 2020 17:01
POSIX.1b timers
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#define TIMERS_NUM 10
PROG := awesome-prog
SOURCES := $(wildcard *.c)
OBJECTS := $(patsubst %c,%o,$(SOURCES))
DEPFILES := $(patsubst %.c,%.d,$(SOURCES))
$(PROG): $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^
%.o: %.d
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#define SUCC 0
#define FULL -1
#define EMPT -2
#define FAIL -3
for (tot = 0; tot < file_size; tot += c) {
c = read(fd, buf + tot, file_size - tot);
if (c == -1 || c == 0) {
if (tot != in_size) {
fprintf(stderr, "could not read the entire input file\n");
fprintf(stderr, "file: %s\n", file_name);
goto ERROR;
}
}
}
#include <stdio.h>
int main(void)
{
char a[24], b[24], i;
for (i = 0; i < 24; i++)
a[i] = i;
for (i = 0; i < 24 / sizeof(int); i++)
*((int *)b + i) = *((int *)a + i);
for (i = 0; i < 24; i++)
printf("%c\n", b[i] + 'a');
@ivanria
ivanria / sizes.c
Last active August 29, 2015 14:23
#include <stdio.h>
int main(void)
{
printf("char: %zu,short: %zu, int: %zu, void* %zu\n"
"long: %zu, long long: %zu\n"
"float: %zu, double %zu, long double %zu\n",
sizeof(char), sizeof(short), sizeof(int), sizeof(void*),
sizeof(long), sizeof(long long),
sizeof(float), sizeof(double), sizeof(long double));
return 0;
@ivanria
ivanria / eratosthenes.sh
Last active August 29, 2015 14:21
sieve of eratosthenes on bash
#!/bin/bash
#https://gist.github.com/ivanria/10b4f1bd7aa79d28de26
declare -a ARRAY
declare -r TRUE=0 #standard for shell return codes
declare -r FALSE=1
parse_cmd() {
if [[ "$1" == "" ]] ; then
echo "need number"
exit 1