Skip to content

Instantly share code, notes, and snippets.

View sutyum's full-sized avatar

Satyam Tiwary sutyum

  • @TechnocultureResearch
  • Boodgaya, India
View GitHub Profile
@sutyum
sutyum / python_decorator_guide.md
Created May 16, 2019 16:59 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@sutyum
sutyum / backup-github.sh
Created April 2, 2021 12:07 — forked from rodw/backup-github.sh
A simple script to backup an organization's GitHub repositories, wikis and issues.
#!/bin/bash
# A simple script to backup an organization's GitHub repositories.
# NOTE: if you have more than 100 repositories, you'll need to step thru the list of repos
# returned by GitHub one page at a time, as described at https://gist.github.com/darktim/5582423
GHBU_BACKUP_DIR=${GHBU_BACKUP_DIR-"github-backups"} # where to place the backup files
GHBU_ORG=${GHBU_ORG-"<CHANGE-ME>"} # the GitHub organization whose repos will be backed up
# (if you're backing up a user's repos instead, this should be your GitHub username); also see the note below about the `REPOLIST` definition around line 48
GHBU_UNAME=${GHBU_UNAME-"<CHANGE-ME>"} # the username of a GitHub account (to use with the GitHub API)
@sutyum
sutyum / preprocessor.c
Last active December 14, 2021 09:35
C macros beyond the usual examples
/*
A single '#' will create a string from the given argument,
regardless of what that argument contains,
while the double '##' will create a new token by concatenating the arguments.
*/
/* Run with compiler flag `-E` using gcc to see the pre-processor output. */
#ifdef ERR
#error "Hey! You've got a compile time error."
@sutyum
sutyum / generic_programming.c
Created December 2, 2021 16:32
Generic Programming in C11
/*
Using _Generic() macro.
Code snippets are directly from:
http://www.robertgamble.net/2012/01/c11-generic-selections.html
Found this link through an answer here:
https://stackoverflow.com/questions/9804371/syntax-and-sample-usage-of-generic-in-c11#17290414
Was introduced to this feature from:
@sutyum
sutyum / syslog.c
Last active December 14, 2021 09:32
Logging to Linux Syslog
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/syslog.h>
#define THREAD_COUNT 128
static const char *g_log_header = "[MYLOGS]";
typedef struct {
@sutyum
sutyum / popen.c
Last active May 29, 2023 18:40
Use `popen()` to use Linux Pipes
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#define NUM_THREADS 1
void log_uname(void) {
FILE *fp;
const char* cmd = "uname -a";
fp = popen(cmd, "r");
@sutyum
sutyum / SHED_FIFO.c
Created December 13, 2021 07:56
Use FIFO scheduling policy and Core affinity in linux
#define _GNU_SOURCE
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <unistd.h>
#include <syslog.h>
@sutyum
sutyum / RTclock.c
Created December 15, 2021 07:47
Real Time clock and nanosleep in linux
/****************************************************************************/
/* Function: nanosleep and POSIX 1003.1b RT clock demonstration */
/* */
/* Sam Siewert - 02/05/2011 */
/* */
/****************************************************************************/
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
@sutyum
sutyum / pio.yml
Created January 15, 2022 17:34
Platformio Github Action (Ignores semantic commits of type 'docs')
name: PlatformIO CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, 'docs')"
steps:
@sutyum
sutyum / platformio.ini
Created January 26, 2022 17:24 — forked from carlosedp/platformio.ini
PlatformIO Renode Integration
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html