Skip to content

Instantly share code, notes, and snippets.

View melvyniandrag's full-sized avatar
🌕
A Picture of Jupiter and 4 of its Moons Through Our Telescope.

melvyniandrag

🌕
A Picture of Jupiter and 4 of its Moons Through Our Telescope.
View GitHub Profile
@melvyniandrag
melvyniandrag / inherited_vector.cpp
Created March 2, 2016 02:10
A little snippet to exercise some C++ skills I dont get to use too often.
/*
* A code sample showing the use of the STL (priority_queue, vector), inheritence from an
* abstract class, templated classes, and templated functors.
* Also, use of c++11 features.
* Also, use of pointers to store inherited elements in a vector of type base_class.
*
* There's alot of interesting C++ stuff in here.
*
* Melvyn Ian Drag ~ 1 March 2015.
* Compile with g++ -std=c++11 -o inherit inherited_vector.cpp
@melvyniandrag
melvyniandrag / threads.cpp
Created January 21, 2017 07:01
this code doesnt behave as it does in the video https://www.youtube.com/watch?v=4Udi9iAyVBQ.
/*
Compiled with
g++ -std=c++11 threads.cpp -pthreads
on ubuntu 15.04 with g++ 4.8
My strange output is:
> ./a.out
Hello from main!
Hello from thread 25615440
@melvyniandrag
melvyniandrag / r_val_ref_example.cpp
Created January 21, 2017 15:37
The destructor is called as described in the concrrency tutorial.
#include <iostream>
#include <string>
class BartoszMilewski{
public:
BartoszMilewski(){
greeting = "Hello";
std::cout << greeting << std::endl;
}
~BartoszMilewski(){
#ifndef BASE_H
#define BASE_H
#include <map>
#include <string>
#include <iostream>
class Base{
public:
const std::map<std::string, std::string>& m;
@melvyniandrag
melvyniandrag / main.cpp
Created August 8, 2017 19:45
Template functions in source
#include "t.h"
int main()
{
myClass mc;
mc.f(1);
mc.f("hi");
}
@melvyniandrag
melvyniandrag / main.cpp
Created August 25, 2017 19:33
Integrating OpenSSL and MPI for testing purposes.
#include <mpi.h>
#include <openssl/evp.h>
#include <openssl/ec.h>
#include <iostream>
#include <cstring>
#include <cassert>
void handleErrors(){
;
}
@melvyniandrag
melvyniandrag / main.cpp
Last active August 29, 2017 18:48
Creating and sharing ECDH keys to create a shared secret with openssl.
/*
Compile me with g++ main.cpp -lssl -lcrypto
The computeNeededSharedMemory() function has alot of stuff that is duplicated in main(). It should be refactored.
Also I forgot to free some stuff at the end. Just add the appropriate calls to the appropriate free methods. For me, its lunchtime
now.
*/
#include <cassert>
#include <string>
@melvyniandrag
melvyniandrag / main.cpp
Last active August 31, 2017 17:06
Test the performance of unordered vs ordered containers.
/*
* Small test of the performance of
* - unordered_set vs set
* - unordered_map vs map
* Compile with g++ main.cpp -std=c++11
* As expected, the unordered versions are faster because they use hash functions, not trees.
*/
#include <unordered_map>
#include <map>
@melvyniandrag
melvyniandrag / ECDH_BC.java
Created August 31, 2017 20:28 — forked from wuyongzheng/ECDH_BC.java
Elliptic curve Diffie–Hellman using Bouncy Castle v1.50 example code
import java.math.BigInteger;
import java.security.PublicKey;
import java.security.PrivateKey;
import java.security.KeyFactory;
import java.security.Security;
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.SecureRandom;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.ECGenParameterSpec;
@melvyniandrag
melvyniandrag / noWorks.cpp
Created November 1, 2017 17:08
function ptrs to member functions and pthreads with member functions.
#include <unistd.h>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <pthread.h>
class Base{
public:
int x;