Skip to content

Instantly share code, notes, and snippets.

View superwills's full-sized avatar

William superwills

View GitHub Profile
@superwills
superwills / OpenSSL RSA encryption sample
Last active November 2, 2022 09:45
Base64 encoding and RSA encryption sample
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/pem.h>
// I'm not using BIO for base64 encoding/decoding. It is difficult to use.
// Using superwills' Nibble And A Half instead
@superwills
superwills / OpenSSL to OpenSSH public key format
Last active December 16, 2015 10:29
Mounir IDRASSI's conversion from OpenSSL to OpenSSH public key format http://www.idrix.fr/Root/Samples/pubkey2ssh.c
/*
* An implementation of convertion from OpenSSL to OpenSSH public key format
*
* Copyright (c) 2008 Mounir IDRASSI <mounir.idrassi@idrix.fr>. All rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
@superwills
superwills / map reverse
Last active December 16, 2015 15:39
Reverses a mapping of map: T -> vector<S> to map: S -> vector<T>
// Reverses a mapping of map: T -> vector<S> to map: S -> vector<T>
template<typename T, typename S>
void reverseMapping( map< T, vector<S> >& oMapping, map< S, vector<T> >& revMapping )
{
for( typename map< T, vector<S> >::iterator iter = oMapping.begin() ; iter != oMapping.end() ; ++iter )
{
for( int i = 0 ; i < iter->second.size() ; i++ )
{
pair< typename map< S, vector<T> >::iterator, bool > res =
revMapping.insert( make_pair( iter->second[i], vector<T>() ) ) ;
@superwills
superwills / XCodeC++Theme
Created April 25, 2013 19:12
XCode C++ color theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0 0 0 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Regular - 12.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0 0 0 1</string>
@superwills
superwills / Point in Polygon
Last active September 7, 2019 15:15
Pt In Poly simple algorithm. Works for convex & concave polygons.
#include <stdlib.h> // MUST BE BEFORE GLUT ON WINDOWS
#ifdef _WIN32
#include <gl/glut.h>
#else
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#endif
// Put this in a separate .h file (called "getopt.h").
// The prototype for the header file is:
/*
#ifndef GETOPT_H
#define GETOPT_H
int getopt(int nargc, char * const nargv[], const char *ostr) ;
#endif
*/
@superwills
superwills / Hugely readable table drawing characters
Last active December 20, 2015 16:09
Hugely readable table drawing characters
From http://en.wikipedia.org/wiki/Box-drawing_character
┘ ┐ ┌ └ ┼ ─ ├ ┤ ┴ ┬ │ • × ⌘ π √ ÷ ² ³ ¼ ½ ¾
A matrix:
┌ ┐
│ 1 0 0 │
│ 0 1 0 │
│ 0 0 1 │
└ ┘
@superwills
superwills / Callback.h
Created August 14, 2013 17:01
Callback.h -- C++ callbacks
#ifndef CALLBACK_H
#define CALLBACK_H
#include <functional>
using namespace std ;
// REQUIRES APPLE LLVM
//Under Apple LLVM compiler 4.0 - Language,
// - C++ Standard Library: choose libc++ (LLVM C++ standard with C++11 support)
// NOT GNU
@superwills
superwills / KeychainSimple.cpp
Last active November 28, 2016 10:26
Call `testKeychain()` from application `didFinishLaunchingWithOptions` or something to run this test code.
bool SecCheck( OSStatus res, const char* msg )
{
if( res==errSecSuccess )
{
printf( "< %s okie dokie >\n", msg ) ; // COMMENT THIS OUT TO SILENCE OK's
}
else
{
printf( "< NOT OK!! >: %s FAILED:\n >> ", msg ) ;
switch( res )
@superwills
superwills / Keychain.hpp
Created October 11, 2013 18:05
SecCRUD operations (SecCreate, SecRead, SecUpdate, SecDelete) for serialization of binary objects with primitive-typed data in them.
#ifndef KEYCHAIN_H
#define KEYCHAIN_H
/*
kSecAttrAccessible - A CFTypeRef (opaque) value that indicates when your app
needs access to the data in a keychain item. You should choose the
most restrictive option that meets your app’s needs so that iOS can protect
that item to the greatest extent possible. For a list of possible values,
see “Keychain Item Accessibility Constants.”