Skip to content

Instantly share code, notes, and snippets.

@rmccullagh
rmccullagh / Makefile
Created December 28, 2014 01:53
Simplest Makefile
objects = main.o Var.o List.o
CCFLAGS = -Wall -Wextra -Wpedantic
main : $(objects)
cc $(CCFLAGS) -o main $(objects)
.PHONY : clean
clean:
rm -f main $(objects)
ifconfig eth0 | grep -P '[0-9].[0-9].[0-9].[0-9]$' | awk '{ print $2 }' | awk '{split($0,a,":"); print a[2]}'
#include <stdio.h>
#include <limits.h> /* for LONG_MAX, INT_MAX */
#include <stdlib.h>
#include <stdbool.h>
#define IS_ASCII_DIGIT(c) (((c >= 48) && (c <= 57)))
long __my_atoi(char* buffer)
{
if(buffer == NULL) {
@rmccullagh
rmccullagh / hello.asm
Created March 31, 2015 02:52
Hello World in x86 compiled on Linux 64 bit
global _start
section .text
_start:
; write (sys_write)
; %rdi
; unsigned int fd
; %rsi
; const char __user *buf
; %rdx
@rmccullagh
rmccullagh / is_power_of_2.c
Created April 3, 2015 22:43
C: Check if a number is a power of 2
#include <stdbool.h>
/*
* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
*/
bool isPowerOf2(unsigned int x)
{
/*
* Convert # into binary
* If there is more than 1 "1", then
@rmccullagh
rmccullagh / my_pop_count.c
Created April 3, 2015 23:46
Hamming Weight
/*
* return the Hamming Weight
*/
int my_pop_count(size_t x)
{
unsigned setBits = 0;
do {
int rem = x % 2;
if(rem == 1) {
setBits++;
@rmccullagh
rmccullagh / popcount.c
Created April 4, 2015 02:12
is_power_of_two
#include <stdbool.h>
#include <stdio.h>
bool is_power_of_two(size_t);
int my_pop_count(size_t);
int main()
{
size_t n = 8;
#include <stdlib.h>
#include <stdio.h>
int main()
{
int r[10];
for(size_t i = 0; i < 10; i++) {
r[i] = i + 1;
}
static void read_file(void)
{
FILE* fp = fopen("a.dat", "rb");
size_t bread = 0;
int data;
if(fp == NULL) {
fprintf(stderr, "Read error\n");
exit(1);
}
function isWebScaleCapable() {
return true;
}
if(isWebScaleCapable()) {
INIT_WEB_SCALE();
}