Skip to content

Instantly share code, notes, and snippets.

View kisssko's full-sized avatar
⁉️

Alexander Gurov kisssko

⁉️
  • Voronezh, Russia
View GitHub Profile
@kisssko
kisssko / tiny_rand.c
Created February 3, 2022 10:09
tiny randomizer
#include <stdint.h>
#include <stdlib.h>
uint32_t tiny_rand(void)
{
uint32_t t = _seed;
t ^= t >> 10;
t ^= t << 9;
t ^= t >> 25;
@kisssko
kisssko / passgen.sql
Last active February 3, 2022 10:18
SQL (sqlite3) password generator
WITH RECURSIVE t(x) AS (SELECT 0 UNION ALL SELECT x + 1 FROM t LIMIT 8 * 16)
SELECT group_concat(substr('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
abs(random()%(62))+1,1), '')
AS PASSWORD FROM t GROUP BY x % 16;
@kisssko
kisssko / gcc_vectors.h
Created December 13, 2021 07:12
gcc vectors
#ifndef __VECTOR
#define __VECTOR(SZ) __attribute__ ((vector_size (SZ)))
#endif
typedef uint8_t u16x4_t __VECTOR(4);
typedef uint16_t u16x2_t __VECTOR(4);
typedef uint8_t u8x8_t __VECTOR(8);
typedef uint16_t u16x4_t __VECTOR(8);
typedef uint32_t u32x2_t __VECTOR(8);
@kisssko
kisssko / incbin.h
Created November 25, 2020 20:01
Include binary file macros
// (T)ype, (V)ariable, (S)ection, (F)ile.
#define INCBIN(T,V,S,F) \
asm \
( \
".globl " #V "\n" \
".section \"" S "\",\"a\"\n" \
".balign 4\n" #V ":\n" \
".incbin \"" F "\"\n" \
); extern T V[]
@kisssko
kisssko / misc_macros.h
Last active February 3, 2022 10:17
Universal useful macros
#ifndef _MISC_MACROS_H_
#define _MISC_MACROS_H_
#define _SET_BIT(V,B) (V) |= (1 << (B))
#define _CLR_BIT(V,B) (V) &= ~(1 << (B))
#define _INV_BIT(V,B) (V) ^= (1 << (B))
#define NIBBLE_PAIR(LN,HN) (((LN) << 0) | ((HN) << 4))
#define PRINT_TYPE_SZ(T) printf("sizeof(%s)=%u\n", #T, sizeof(T))
@kisssko
kisssko / sdcc_zx.h
Last active November 25, 2020 19:50
ZX-Spectrum useful definition stuff
#ifndef SDCC_ZX_H
#define SDCC_ZX_H
#include <stdint.h>
// ### __z88dk_fastcall call convention in SDCC ###
// 32 bit: input - DEHL, output - DEHL.
// 16 bit: input - HL, output - HL.
// 8 bit: input - L, output - L.
@kisssko
kisssko / const.c
Created December 11, 2019 10:50 — forked from burczyk/const.c
const int VS int const
The trick is to read the declaration backwards (right-to-left):
const int a = 1; // read as "a is an integer which is constant"
int const a = 1; // read as "a is a constant integer"
Both are the same thing. Therefore:
a = 2; // Can't do because a is constant
The reading backwards trick especially comes in handy when you're dealing with more complex declarations such as:
const char *s; // read as "s is a pointer to a char that is constant"
@kisssko
kisssko / rev8.h
Last active February 3, 2022 10:11
REV8
#define REV8(V) ((((V) & 0x01) << 7) | \
(((V) & 0x02) << 5) | \
(((V) & 0x04) << 3) | \
(((V) & 0x08) << 1) | \
(((V) & 0x10) >> 1) | \
(((V) & 0x20) >> 3) | \
(((V) & 0x40) >> 5) | \
(((V) & 0x80) >> 7))
@kisssko
kisssko / drawline.c
Created May 6, 2018 21:22
Speed-optimized Bresenhem algorythm
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void plot(int x, int y, int c)
{
gotoxy(x+1,y+1);
putchar(c);
putchar(8);
@kisssko
kisssko / ReadLinesIterator.cs
Created May 6, 2018 19:25
ReadLines iterator (cs)
using System;
using System.Text;
namespace System.IO
{
internal class ReadLinesIterator : Iterator<string>
{
private readonly string _path;
private readonly Encoding _encoding;