Skip to content

Instantly share code, notes, and snippets.

@vo
vo / gist:9541767
Created March 14, 2014 03:41
Programming practice: Simple C++ Hash table
#include <iostream>
#include <sstream>
struct entry {
std::string data;
int value;
entry * next;
};
unsigned int hash(std::string s, int hash_size) {
@vo
vo / qsort.c
Created March 13, 2014 21:42
Simple In-Place Quicksort in C (Just programming practice)
#include <cstdio>
#include <cstdlib>
#include <ctime>
void sort(int * a, size_t n) {
if (n < 2)
return;
int p = a[n/2];
int *l = a;
int *r = a + n-1;
@vo
vo / pthreads.cpp
Created March 13, 2014 07:24
Stupid simple Pthread example for reference
#include <iostream>
#include <cstdio>
#include <pthread.h>
#include <unistd.h>
typedef struct {
int thread_num;
} data_t;
void *task (void * data) {
@vo
vo / override_rc.py
Created March 5, 2014 07:03
Quick hack to override RC over MAVLink with arrow keys
#!/usr/bin/env python
import sys, os
from optparse import OptionParser
import Tkinter as tk
# tell python where to find mavlink so we can import it
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../mavlink'))
from pymavlink import mavutil
@vo
vo / listener.py
Created March 5, 2014 07:02
Quick hack to position hold with MAVLink using external webcam
#!/usr/bin/env python
import sys, os, socket, pickle
from time import time
from optparse import OptionParser
UDP_IP = "127.0.0.1"
UDP_PORT = 31200
# tell python where to find mavlink so we can import it
@vo
vo / gist:9331392
Created March 3, 2014 18:27
Rotating an NxN array 90 degrees in-place with a transpose and flip operation
#include <iostream>
#include <cstdio>
#define DIM 5
void swap(int s[DIM][DIM], int i, int j, int k, int l) {
char c = s[i][j];
s[i][j] = s[k][l];
s[k][l] = c;
}
@vo
vo / gist:9331376
Created March 3, 2014 18:26
Checking if one string is a permutation of another
#include <iostream>
void build_histogram(std::string s, int * m) {
size_t len = s.length();
for(int i = 0; i < len; ++i)
m[s[i]] +=1;
}
bool check_permutation(std::string s1, std::string s2)
{
@vo
vo / gist:9331349
Last active February 13, 2023 13:22
Simple Mavlink Reader in Python using pymavlink
#!/usr/bin/env python
import sys, os
from optparse import OptionParser
# tell python where to find mavlink so we can import it
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../mavlink'))
from pymavlink import mavutil
def handle_heartbeat(msg):
@vo
vo / gist:9284932
Created March 1, 2014 04:04
Different ways to check for duplicates in a string
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <climits>
// using STL MAP
bool duplicate_check_maphist(std::string s)
{
std::map<char, int> h;
@vo
vo / divide_naive.c
Last active August 29, 2015 13:56
Divide two unsigned ints without division operator
#include <stdio.h>
typedef unsigned int UINT;
// does not handle overflow or negative numbers
UINT divide_naive(UINT a, UINT b)
{
UINT result;
while (b < a) {
UINT k=0, b2k = b;
while(b2k << 1 < a)