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 / main.cpp
Created March 1, 2018 20:07
arrays, pointers, references
#include <iostream>
#include <iomanip>
typedef char myArr[12];
void printInfo( myArr &arr, myArr arr2, myArr* arr3 )
{
std::cout << std::setw(10) << "arr: " << std::setw(20) << arr << std::setw(10) << " arr2: " << std::setw(20) << arr2 << std::setw(10) << " arr3: " << std::setw(20) << arr3 << std::endl;
std::cout << std::setw(10) << "&arr: " << std::setw(20) << &arr << std::setw(10) << " &arr2: " << std::setw(20) << &arr2 << std::setw(10) << " &arr3: " << std::setw(20) << &arr3 << std::endl;
std::cout << std::setw(10) << "arr[0]: " << std::setw(20) << arr[0] << std::setw(10) << " arr2[0]: " << std::setw(20) << arr2[0] << std::setw(10) << " arr3[0]: " << std::setw(20) << arr3[0] << std::endl;
std::cout << std::setw(10) << "&arr[0]: " << std::setw(20) << &arr[0] << std::setw(10) << " &arr2[0]: " << std::setw(20) << &arr2[0] << std::setw(10) << " &arr3[0]: " << std::setw(20) << &arr3[0] << std::endl;
@melvyniandrag
melvyniandrag / main.cpp
Created February 21, 2018 16:00
pass multiple args to a pthread
#include <pthread.h>
#include <iostream>
class A
{
public:
A( int _i, int *_p ) : i( _i ), p( _p ){}
int i;
int *p;
void squareMyPtr()
{
@melvyniandrag
melvyniandrag / main.cxx
Last active January 15, 2018 17:25
lambda functions
#include "template.h"
#include <vector>
#include <iostream>
int main(){
std::vector<int> V{1, 2, 3, 4, 5};
std::vector<int> filtered = filter( [](int i){return i %2 == 0;}, V);
for( auto f : filtered ){
std::cout << f << std::endl;
}
class A( object ):
def __init__( self ):
print("A")
super( A, self ).__init__()
class B( object ):
def __init__( self ):
print("B")
super( B, self ).__init__()
@melvyniandrag
melvyniandrag / aes256.java
Last active November 7, 2017 17:55
aes 256 in grypt / java
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import java.util.Base64;
public class Test{
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
@melvyniandrag
melvyniandrag / gcrypt_aes256.cpp
Created November 7, 2017 17:16
aes 256 in grypt
#include <cassert>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <gcrypt.h>
#include <string>
@melvyniandrag
melvyniandrag / pthread.cpp
Created November 1, 2017 17:39
start p thread with static wrapper around non static function
#include <unistd.h>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <pthread.h>
class Base{
public:
int x;
@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;
@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 / 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>