Skip to content

Instantly share code, notes, and snippets.

@ilansmith
ilansmith / macros.h
Last active October 27, 2017 22:45
Everything macro
/* How to return a value from a macro */
#define FUNC(num1, num2) ({ \
int __ret; \
do { \
__ret = (num1) < (num2) ? 0 : 1; \
} while (0); \
__ret; \
})
@ilansmith
ilansmith / arm_stack_size.c
Last active October 28, 2015 11:52
Chagne kernel stack size for arm processor
diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index 870d7ff..5c5dc5b 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -15,8 +15,8 @@
#include <linux/compiler.h>
#include <asm/fpstate.h>
-#define THREAD_SIZE_ORDER 1
-#define THREAD_SIZE 8192
@ilansmith
ilansmith / git_aliases_setup.sh
Created January 9, 2016 21:10 — forked from AvnerCohen/git_aliases_setup.sh
Random Git aliases and commands to
# Command: GLOG
# Description: alias that creates a nice and easy on eye history log with graph indication of merge commits and branches
git config --global alias.glog "\!git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative ; true"
# Run:
git glog
# Command: LASTWORKS
# Description: Lists the last 10 branches you worked on
git config --global alias.lastworks "for-each-ref --count=10 --sort=-committerdate refs/heads/"
@ilansmith
ilansmith / commit-msg
Created October 9, 2016 21:45
A git hook that automatically adds a change-id to the commit message.
#!/bin/sh
# From Gerrit Code Review 2.1.2-rc2-33-g7e30c72
#
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ilansmith
ilansmith / glibc_version.c
Last active October 30, 2016 12:56
Get glibc version
#include <stdio.h>
#include <gnu/libc-version.h>
int main (void)
{
puts(gnu_get_libc_version());
return 0;
}
@ilansmith
ilansmith / colours.c
Created August 19, 2017 11:24
Shell Colours
#include <stdio.h>
#define CLEAR "\033[00;00;00m"
static void p_colour(int c1, int c2)
{
char col[10];
sprintf(col, "\033[%d;%dm", c1, c2);
printf("\"\\033[%d;%dm\" = %scolour%s\n", c1, c2, col, CLEAR);
@ilansmith
ilansmith / print_in_place.c
Created August 19, 2017 22:13
Print "moving" objects (advancing timeline, rotating star, etc...)
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/select.h>
#include <stdarg.h>
#define CURSOR_DISSABLE "\E[?25l"
#define CURSOR_ENABLE "\E[?25h"
#define ARRAY_SZ(ARR) (sizeof(ARR) / sizeof(ARR[0]))
@ilansmith
ilansmith / dirent.c
Created September 26, 2017 06:50
An example of how to manipulate a directory entry
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <stdio.h>
static int path_scan(char *path)
{
DIR *d;
struct dirent *ent;
@ilansmith
ilansmith / time_limit.bat
Last active June 15, 2019 04:35
Set Windows 10 local user time restrictions
@echo off
set MORNING=6:00am-8:00am
set SCHOOL=8:00am-1:00pm
set AFTERNOON=1:00pm-6:00pm
set EVENING=6:00pm-12:00am
set NIGHT=12:00am-6:00am
set LIMIT=SU-SA,%AFTERNOON%;F,%EVENING%;SA,%MORNING%,%SCHOOL%
rem echo MORNING:%MORNING%
@ilansmith
ilansmith / my_getopt.c
Last active October 18, 2018 23:21
getopt() for optional argument
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#define ALIGN_OPTIONAL_ARGUMENT(_argc, _argv, _optstring, _optarg, _optind) \
do { \
if (!(_optarg) && (_optind) < (_argc) && \
(((_argv)[(_optind)][0] != '-') || \
!strchr(_optstring, (_argv)[(_optind)][1]))) { \
(_optarg) = (_argv)[(_optind)++]; \