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 / 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 / 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 / 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{
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 / 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;
}
@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.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 / client.c
Last active March 29, 2018 15:31
server / client with unix sockets
/*
** client.c -- a stream socket client demo
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
@melvyniandrag
melvyniandrag / dbusVLC.py
Last active April 2, 2018 18:59
Control vlc over dbus
import dbus
import dbus.mainloop.glib
import time
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus=dbus.SessionBus()
obj = bus.get_object("org.mpris.MediaPlayer2.vlc",
"/org/mpris/MediaPlayer2")
print(dir(obj))
@melvyniandrag
melvyniandrag / cppDbusVlc.cpp
Created April 10, 2018 21:14
use dbus to hit the play button in vlc
/*
g++ cppdbus.cpp -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ -lglib-2.0 -lgio-2.0 -lgobject-2.0
*/
#include <iostream>
#include <gio/gio.h>
int main()
{
GDBusConnection* conn = NULL;
GError* error = NULL;