Skip to content

Instantly share code, notes, and snippets.

View ardeshir's full-sized avatar
🎯
Focusing

sepahsalar ardeshir

🎯
Focusing
View GitHub Profile
@ardeshir
ardeshir / step
Created November 5, 2013 20:04
Stepping into states
#include <stdio.h>
enum states { before, inside, after };
void step(enum states *state, int c)
{
if(c == '\n') {
putchar('\n');
*state = before;
} else
@ardeshir
ardeshir / FileWalker
Created November 5, 2013 20:06
Get a file from the cmd line and walk the file system.
import java.io.*;
import java.util.*;
public class FileWalker {
public static void main(String[] args) {
for( int i = 0; i < args.length; i++ ) {
File f = new File(args[i]);
if(f.exists()) {
System.out.println("Name: " + f.getName());
@ardeshir
ardeshir / Tree
Created November 5, 2013 20:10
Print the tree structure of file location
#!/usr/bin/perl
use strict;
use warnings;
use autodie ':all';
use File::Spec::Functions qw(catdir splitdir);
# The starting directory will be passed on the command line
# Otherwise, use the current directory.
@ardeshir
ardeshir / Birthdays
Last active December 27, 2015 12:19
Calculate the possible match of someone's birthday with yours
#include <math.h>
#include <stdio.h>
typedef struct {
double one_match;
double none_match;
} bday_struct;
int upto = 40;
@ardeshir
ardeshir / Object Oriented C
Created November 5, 2013 20:14
Create Objects and Methods of Objects in C
#include <stdio.h>
#include <assert.h>
/* #include "New.h"
#include "Object.h"
#include "Set.h" */
#if ! defined MANY || MANY < 1
#define MANY 10
#endif
@ardeshir
ardeshir / libtools
Created November 5, 2013 20:16
Little Lib of C++ functions
/* libtools.cpp - library of C++ procedures */
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#define MAX_NAME 255 /* maximum length of program or file name */
static char prog_name[MAX_NAME+1]; /* used in error messages */
@ardeshir
ardeshir / Simple LinkedList
Created November 5, 2013 20:19
Simple Linked List
#include <stdlib.h>
#include <stdio.h>
#ifndef __cplusplus
typedef char bool;
#define true 1
#define false 0
#endif
struct list_element {
@ardeshir
ardeshir / cmdline
Created November 5, 2013 20:21
AWS Python Tool
import os
import time
import boto
import boto.manage.cmdshell
def launch_instance(ami='ami-7341831a',
instance_type='t1.micro',
key_name='us-west-key2',
key_extention='.pem',
key_dir='~/Documents/Keys',
@ardeshir
ardeshir / Goroutine
Created November 5, 2013 20:22
Simple Go routine Example
package main
import (
"fmt"
"time"
)
type Ball struct { hits int }
@ardeshir
ardeshir / Inferno
Last active December 27, 2015 12:28
Derived from Inferno include/kern.h and Plan 9 from User Space include/libc.h
/*
Derived from Inferno include/kern.h and
Plan 9 from User Space include/libc.h
http://code.google.com/p/inferno-os/source/browse/include/kern.h
http://code.swtch.com/plan9port/src/tip/include/libc.h
Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved.
Portions Copyright © 2001-2007 Russ Cox. All rights reserved.