Skip to content

Instantly share code, notes, and snippets.

View barrysteyn's full-sized avatar

Barry Steyn barrysteyn

View GitHub Profile
@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 / Base64.md
Last active April 9, 2024 08:29
OpenSSL Base64 En/Decode: Portable and binary safe.

OpenSSL Base64 Encoding: Binary Safe and Portable

Herewith is an example of encoding to and from base64 using OpenSSL's C library. Code presented here is both binary safe, and portable (i.e. it should work on any Posix compliant system e.g. FreeBSD and Linux).

License

The MIT License (MIT)

Copyright (c) 2013 Barry Steyn

@barrysteyn
barrysteyn / README.md
Last active January 22, 2023 22:43
C/C++ Examples For Understanding

Introduction

These toy examples are for helping with understanding C/C++. There is an excellent C++ samples site which demonstrates many useful things.

@barrysteyn
barrysteyn / svn-to-git.md
Last active December 26, 2022 22:32
Migrate From SVN To GIT
@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 / rotate_matrix.cpp
Last active March 16, 2021 06:18
Rotate a matrix by 90 degrees in place: http://leetcode.com/onlinejudge#question_48
class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
int N = matrix.size()-1,
temp = 0;
for (int i=0; i < N; i++) {
for (int j=0; j+i < N; j++) {
//Only one temp variable is needed
@barrysteyn
barrysteyn / recover_ip_address.cpp
Created July 1, 2013 14:44
Leetcode problem: Recover IP Addresses
/*
* This is a classic backtracking algorithm. It is made difficult due to the following:
* 1) There is a special case, namely 0
* 2) Normally, backtracking employs a for loop, this needs a while loop. Therefore
* conditions for ending the recursion is not normal
*
* All ip addresses consist of octets, which is between 0 and 255. So any number within this
* range should be selected for our ip address. If however we cannot pick such a number
* then we must back track
* Time Complexity O(n^2) Space O(1)
@barrysteyn
barrysteyn / Readme.md
Created July 3, 2013 18:53
Leetcode: Reverse Linked List II
@barrysteyn
barrysteyn / Readme.md
Last active March 11, 2018 18:01
LeetCode: Flatten Binary Tree To Linked List
@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 =