Skip to content

Instantly share code, notes, and snippets.

@irondoge
irondoge / environ.c
Last active July 8, 2016 18:55
get a pointer to the environment variables from any function [compilation: gcc -W -Wall -Wextra -std=c89 environ.c]
#include <stdio.h>
int main(int ac, char **av, char **env)
{
extern char **environ;
(void)ac;
(void)av;
printf("%p = %p | => %s\n", environ, env, environ[0]);
return (0);
@irondoge
irondoge / base_realloc.c
Last active July 10, 2016 19:06
simple base conversion with realloc [compilation: gcc -W -Wall -Wextra -std=c89 base_realloc.c]
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void push_front(char **str, char c)
{
char *ret;
ret = malloc(sizeof(char) * (strlen(*str) + 2));
*ret = c;
@irondoge
irondoge / base_buffer.c
Last active July 10, 2016 19:08
simple base conversion with buffer [compilation: gcc -W -Wall -Wextra -std=c89 base_buffer.c]
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
# define push_front(buff, c) (memmove(buff + 1, buff, (strlen(buff) + 2)), *buff = c)
char *convert(int o, char *buff, char const *base)
{
*buff = 0;
while (o > 0)
@irondoge
irondoge / polymorphism.c
Created July 8, 2016 19:01
acces parent-struct fields from a child-struct [compilation: gcc -W -Wall -Wextra -std=c89 -fms-extensions polymorphism.c]
#include <stdio.h>
struct poly_parent
{
int a;
char b;
void *c;
};
struct poly_child
@irondoge
irondoge / range.c
Created July 8, 2016 19:05
array definition by range [compilation: gcc -W -Wall -Wextra -std=c89 range.c]
#include <stdio.h>
int main()
{
int omg[10] = { [0 ... 4] = 42, [5 ... 9] = 10 };
printf("%d", omg[3]);
return (0);
}
@irondoge
irondoge / README.md
Last active July 8, 2016 23:14
README generic template

This is the project name

This is a short description of your Project.

Screenshot

Screenshot software

Code Example

Show what the library does as concisely as possible, developers should be able to figure out how your project solves their problem by looking at the code example. Make sure your code is short and concise, prefer pseudo code.

This is pseudo code:

@irondoge
irondoge / Makefile
Last active October 14, 2016 23:29
Makefile generic template for binary
#
# paths
#
SRCDIR := sources
LIBDIR := lib
INCDIRS := includes $(LIBDIR)/includes
#
# compilation options
#
@irondoge
irondoge / Makefile
Last active October 14, 2016 23:29
Makefile generic template for shared object
#
# paths
#
SRCDIR := sources
INCDIR := includes
#
# compilation options
#
CC := gcc
@irondoge
irondoge / extract.txt
Last active October 14, 2016 23:27
extract Makefile variables
$ cat Makefile
NAME := star my github repo's pliz
NAME2 = OK
get-%:; $($*)
$ make -n get-NAME
star my github repo's pliz
$ make -n get-NAME2
@irondoge
irondoge / dims.py
Created October 15, 2016 14:12
Get python list dimensions number
def dims(lst):
ct = 1
while list in [ type(i) for i in lst ]:
lst = sum([ i for i in lst if type(i) == list ], [])
ct += 1
return ct