Skip to content

Instantly share code, notes, and snippets.

@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 / 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
#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) {
ifconfig eth0 | grep -P '[0-9].[0-9].[0-9].[0-9]$' | awk '{ print $2 }' | awk '{split($0,a,":"); print a[2]}'
@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)
#include <iostream>
#include <deque>
#include <algorithm>
#include <iterator>
#include <cstring>
#include <vector>
using namespace std;
// non-breaking-s-pace
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#define NL std::cout << std::endl
using namespace std;
void __(const char *s) {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*
* const char* const read only
* const char* is read/write
*/
int find_str_in_str(const char* const base, const char* const sub)
#include <stdio.h> // fprintf
#include <stdlib.h> // malloc
#include <string.h> // strlen
#include <ctype.h> // toupper, tolower
/*
* a string is an array of characters, in C, all arrays
* are always passed never passed value, always a pointer to
* the variable
* This is why the caller does not need to call the function like:
@rmccullagh
rmccullagh / camel_case_rev.js
Created October 22, 2014 19:51
Reverse Camel Case implementation
function camel_case_rev(word)
{
if(! word)
return;
word = (word).toString();
var ret = "";
for(var i = 0; i < word.length; i++)