Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <string>
using namespace std;
void recursive(string s, int count, int limit)
{
if (count < limit)
{
for (int i = 0; i < count; i++)
{
@mesbahamin
mesbahamin / pointers.cpp
Last active March 20, 2017 19:31
Basic examples of pointers, the dereference operator, and the address of operator.
#include <iostream>
using namespace std;
int main()
{
int num;
cout << "The address of 'num': " << &num << endl;
@mesbahamin
mesbahamin / arrays_pointers_functions.c
Created November 20, 2016 01:32
Some examples of functions handling multi-dimensional arrays and pointers.
/* Some examples of functions handling arrays and pointers
* Created by Amin Mesbah
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
@mesbahamin
mesbahamin / dict_example.py
Created September 9, 2016 23:03
An example of using nested python dictionaries to store log entries
from pprint import pprint
# Create an empty dictionary:
log_entry = {}
# Add a key called 'ipaddr' to the dict, and assign
# a value to it:
log_entry['ipaddr'] = '192.168.1.1'
# Add more keys and corresponding values:
{
"key":1234,
"key":5678,
"key":"abcd",
"bork":"asdf",
"bork":"dfsd"
}
@mesbahamin
mesbahamin / value_reference_functions.cpp
Created July 7, 2016 06:47
Example of passing parameters by value and by reference
#include <iostream>
using namespace std;
// These are the function prototypes
int addTenByValue(int num);
int addTenByReference(int &num);
void addTenNoReturn(int &num);
int main()
@mesbahamin
mesbahamin / listdictsearch.py
Last active May 23, 2016 23:11
Searching a dict and ensuring either zero or one results.
# This is a simplified version of a more complex problem I'm trying to solve.
# search() seems to have the desired behavior (see docstring), but seems a bit clumsy.
# Is there a more pythonic way to do this?
def search(my_list, my_dict, search_term):
"""Example Output:
---
>>> l = [1, 2, 3, 4]
>>> d = {1: "foo", 2: "bar", 3: "baz", 4: "baz"}
>>> search(l, d, "borkborkbork")
@mesbahamin
mesbahamin / rngfail.cpp
Created September 22, 2015 22:35
Confused about why this RNG doesn't ever generate a random first number.
// When this program is executed multiple times, the first number generated is always the same.
// The other numbers in the 5 number sequence are random.
// I'm confused about why the first number isn't random
#include <iostream>
#include <random>
#include <time.h>
using namespace std;