Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe H. Rahme joehakimrahme

  • Red Hat
  • Milano
View GitHub Profile
View fork1.c
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv){
fork();
/* The function getpid() returns the PID of the current process */
fprintf(stdout, "I'm a process, my PID is: %d", getpid());
return EXIT_SUCCESS;
@joehakimrahme
joehakimrahme / example1.c
Created Feb 2, 2011
First use of the fork() function
View example1.c
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char** argv){
fork();
fprintf(stdout, "Hello World");
return EXIT_SUCCESS;
}
View gist:2642890
function eat(food)
print ("I eat " .. food)
end
function drink(food)
print ("I drink " .. food)
end
function swallow (food)
func = {[true] = eat,
@joehakimrahme
joehakimrahme / gist:2702849
Created May 15, 2012
Lua multiline comments
View gist:2702849
--[[
print("hello world")
--]]
-- By adding a single hypen at the beginning of the top line, you effectively uncomment the whole block:
---[[
print("hello world")
--]]
View table-ex1.lua
t1 = { a=1, b="hello" }
print (t1["a"]) -- outputs "1"
t2 = { [1<4] = "foo", [1<10] = "bar" }
print (t2[true]) -- outputs "bar"
View table-ex2.lua
t3 = {1, 4, 5, 2, 31}
print (t3[3]) -- will output "5"
t4 = {a = "foo", b = 3}
print (t4.a) -- will output "foo"
print (t4.b) -- will output "3"
View tableswitch.lua
abs = function(x)
test = {
[true]=-x,
[x>0]=x,
[x==0]=0}
return test[true]
end
print (abs(-3)) -- outputs "3"
@joehakimrahme
joehakimrahme / K&R: 1.21
Created Jun 4, 2012
Entab: Replace blanks by tabs
View K&R: 1.21
#include <stdio.h>
#define TABSTP 4
/* TODO: read this string from argv,
to test different scenarios */
char* input_str = "Something to test it";
int nexttbstp (int position);
int printblank(int start, int end);
@joehakimrahme
joehakimrahme / entab.c
Created Jun 4, 2012
K&R (1.21): Replace blanks by tabs
View entab.c
#include <stdio.h>
#define TABSTP 4
/* TODO: read this string from argv,
to test different scenarios */
char* input_str = "Something to test it";
int nexttbstp (int position);
int printblank(int start, int end);
@joehakimrahme
joehakimrahme / size.c
Created Jun 4, 2012
K&R (2.1): Size of types
View size.c
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
signed short i, min, max;
i = min = max = 0;
while (++i) {