Skip to content

Instantly share code, notes, and snippets.

View MosheBerman's full-sized avatar

Moshe MosheBerman

View GitHub Profile
@MosheBerman
MosheBerman / sum3.cpp
Last active December 16, 2015 06:39
An example where we wrap a sum(int, int) call in a wrapper function.
/* Prototypes */
int sum(int, int);
void wrapper(int, int);
/* Main program */
int main()
{
wrapper(1,1); // We pass in the two values instead.
@MosheBerman
MosheBerman / sum4.cpp
Created April 16, 2013 04:01
An example where we return the value received by the wrapper function.
/* Prototypes */
int sum(int, int);
int wrapper(int, int);
/* Main program */
int main()
{
int x = wrapper(1,1); // We pass in the two values instead.
@MosheBerman
MosheBerman / gist:5645752
Created May 24, 2013 18:57
forkwait main
main(int argc, char* argv[])
{
// Generate a random number between MINFORKS and MAXFORKS
unsigned int seed = generateSeed(0);
int n = rand_r(&seed) % MAXFORKS + MINFORKS;
// Time elapsed
long time = 0;
time = elapsedTime((int)time);
@MosheBerman
MosheBerman / gist:5646116
Created May 24, 2013 19:59
Why is my second loop logging in order?
int
main(int argc, char* argv[])
{
// Wire up the timer
long time = elapsedTime(0);
/* Generate a random number between MINFORKS and MAXFORKS
*/
unsigned int seed = generateSeed(0);
/*
* Loop through the processes and wait for them
* to terminate. Then print the childid, and the
* the pid.
*/
int status = NULL;
for (int i = 0; i < n; i++)
{
main(int argc, char* argv[])
{
// Wire up the timer
long time = elapsedTime(0);
/* Generate a random number between MINFORKS and MAXFORKS
*/
unsigned int seed = generateSeed(0);
int n = rand_r(&seed) % MAXFORKS + MINFORKS;
@MosheBerman
MosheBerman / test.m
Last active December 17, 2015 20:29
A demo of the arrayDictionaryArray category pair.
// Code:
#import "ArrayDictionaryArray.h"
- (void)sampleConversion
{
NSArray *array = @[@"Hello", @"I", @"Am", @"Deep", @"Blue"];
NSDictionary *dictionary = [array dictionary];
@MosheBerman
MosheBerman / Toodles.py
Last active December 18, 2015 10:09
There's a syntax error on line 30, but I have no clue what the error is. Help?
import os
import keyword
import sys
class Toodles:
def walkAndList(directory):
for dirname, dirnames, filenames in os.walk(directory):
@MosheBerman
MosheBerman / snippet.m
Created October 30, 2013 17:36
iOS 6 margins on iOS 7
- (void)applyLegacyBoundries
{
/* In iOS 7, UIKit will automatically
* put content beneath navigation bars.
* It also tries to pad scroll views
* and table views to make them
* scroll nicely beneath them.
*
* These two checks will fix them.
*
/**
* This class extends the Stack
* so that there's a pushdown(i)
* method which copies the elements
* at index 0 and inserts it and index i.
* All items beneath index i are pushed down.
*
*/
import java.util.Stack;