Skip to content

Instantly share code, notes, and snippets.

View barrysteyn's full-sized avatar

Barry Steyn barrysteyn

View GitHub Profile
@barrysteyn
barrysteyn / bubblesort.py
Created November 16, 2012 22:31
Bubble sort algorithm in pythong
for i in range(len(array_to_sort),0,-1):
for j in range(i-1):
if (array_to_sort[j] > array_to_sort[j+1]):
temp = array_to_sort[j];
array_to_sort[j] = array_to_sort[j+1];
array_to_sort[j+1] = temp;
@barrysteyn
barrysteyn / convert_text_to_decimal.py
Created December 1, 2012 19:39
Convert text to decimal
BITS = ('0', '1')
ASCII_BITS = 8
def bit_list_to_string(b):
"""converts list of {0, 1}* to string"""
return ''.join([BITS[e] for e in b])
def seq_to_bits(seq):
return [0 if b == '0' else 1 for b in seq]
@barrysteyn
barrysteyn / Base64Decode.c
Last active April 23, 2024 09:50
Base64 Encoding/Decoding with the OpenSSL c api
//Decodes Base64
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <string.h>
#include <stdio.h>
int calcDecodeLength(const char* b64input) { //Calculates the length of a decoded base64 string
int len = strlen(b64input);
int padding = 0;
@barrysteyn
barrysteyn / Node_Upstart_NVM
Created January 6, 2013 14:27
Running a Node process under NVM that uses upstart.
start on runlevel [2345]
stop on runlevel [06]
setuid devuser #don't run the process as root. You are asking for trouble if you do
setgid devuser
env NODEFOLDER=/home/dev/node-script
script
chdir $NODEFOLDER
@barrysteyn
barrysteyn / Python_VirutalEnv_With_Upstart
Created January 6, 2013 18:33
Using Python with a VirtualEnv in Upstart
start on runlevel [2345]
stop on runlevel [06]
setuid devuser
setgid devuser
exec /usr/local/bin/uwsgi --master --socket 127.0.0.1:3031 --pythonpath "/home/dev/python-script" --file "/home/dev/python-script/script.py" --callable app --processes 20 --virtualenv "/home/dev/.virtualenvs/python-script" --enable-threads
start on startup
@barrysteyn
barrysteyn / main.c
Last active August 6, 2017 02:08
Merge sort example in C
#include<iostream>
#include "mergesort.c"
using namespace std;
int main(int argc, char** argv) {
int num;
cout << "How many numbers do you want to sort: ";
cin >> num;
int a[num];
for (int i = 0; i < num; i++) {
@barrysteyn
barrysteyn / Quick Sort.md
Last active September 4, 2016 03:24
The canonical example for Quick Sort

Quick Sort

Notes here

@barrysteyn
barrysteyn / gist:5413430
Created April 18, 2013 15:03
Fibonacci - Recursive
void fib(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
return fib(n-1) + fib(n-2);
}
@barrysteyn
barrysteyn / Leetcode: Search In A Sorted Array.md
Last active November 26, 2017 14:33
Leetcode online judge "Word Search" solution.

LeetCode Problem: Word Search\

http://oj.leetcode.com/problems/word-search/

Problem Description

Given a 2D board and a word, find if the word exists in the grid.

The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.

For example, Given board =

@barrysteyn
barrysteyn / rotate_list.cpp
Created June 25, 2013 19:27
Rotate List, from LeetCode
/**
* In an interview, the following questions should be asked:
* (1) What happens if k is longer than the list size
* (2) Edge cases (if head is NULL and k may be zero)
*
* Analysis: (where n is the number of nodes in the list)
* Time: O(n)
* Space: O(1)
*/