Skip to content

Instantly share code, notes, and snippets.

@stephenmm
stephenmm / passing_by_example.cpp
Created May 31, 2012 02:30
Working example of passing by value, reference and pointer in every combination.
// g++ passing_by_example.cpp -o passing_by_example.x && ./passing_by_example.x
#include <iostream>
using namespace std;
int main(){
int Bats = 1;
int *pB = &Bats;
int& rB = Bats;
void PassByValue(int b);
@stephenmm
stephenmm / dynamic_cast_example.cpp
Created May 31, 2012 16:59
Using dynamic_cast in a few examples to show how its used. (polymorphic)
// g++ dynamic_cast_example.cpp -o dynamic_cast_example.x && dynamic_cast_example.x
#include <iostream>
using namespace std;
class A { public: virtual string class_string() { return "Class A"; } };
class B : public A { public: virtual string class_string() { return "Class B"; } };
class C : public A { public: virtual string class_string() { return "Class C"; } };
class D : public C { public: virtual string class_string() { return "Class D"; } };
// dynamic_cast returns NULL if the cast is impossible and the type is a pointer
@stephenmm
stephenmm / chess_test.cpp
Created August 11, 2012 21:33
Start of simple chess analysis tool
/*
g++ -c -Wall -g chess_test.cpp && \
g++ -g -o chess_test.exe chess_test.o &&\
./chess_test.exe
*/
#include <iostream>
#include <iomanip>
#include <list>
#include <vector>
using namespace std;
@stephenmm
stephenmm / named_func_params.c
Created May 29, 2013 02:48
This is an example of getting named function parameters with c99 code. Didn't work out of the box for C++ but I think there may be a way to get it to work for C++ as well.
/** To compile:
gcc -Wall -c named_func_params.c -o named_func_params.o && \
gcc named_func_params.o -lm -o named_func_params.x && \
named_func_params.x
*/
#include<stdio.h>
typedef struct funcParams_s{
int UID;
char uid_char[24];
@stephenmm
stephenmm / cnvrt.pl
Created July 10, 2013 19:25
Simple script to convert numbers to binary hex or decimal. Can be used directly or used as a module for other scripts.
#!/usr/bin/perl -w
# AUTHOR: Stephen Meckley 7/10/2013
package cnvrt;
use strict;
use warnings;
__PACKAGE__->main(@ARGV) unless caller;
sub main {
@stephenmm
stephenmm / RenameCurrentFile.vim
Created July 11, 2013 20:37
RenameCurrentFile with auto-completion
function! RenameCurrentFile(newName)
let l:currentFile = expand("%:p")
silent! exe "saveas " . a:newName
if delete(l:currentFile)
echoerr "Could not delete " . l:currentFile
endif
endfunction
command! -nargs=1 -complete=file -bang RenameCurrentFile :call RenameCurrentFile("<args>")
noremap <Leader>rf :RenameCurrentFile <C-R>=expand("%:p")<CR>
"
" You will have to restart vim for this to take effect. In any case
" it is a good idea to read ":he new-filetype" so that you know what
" is going on, and why the above lines work.
"
" Written originally by Dominic Mitchell, Jan 2006.
" happygiraffe.net
"
" Modified by Aaron Bieber, May 2007.
" blog.aaronbieber.com
" This:
if not session.counter:
session.counter = 1
else:
session.counter += 1
" Is equvalent to this:
session.counter = (session.counter or 0) + 1
"""
This recipe describes how to handle asynchronous I/O in an environment where
you are running Tkinter as the graphical user interface. Tkinter is safe
to use as long as all the graphics commands are handled in a single thread.
Since it is more efficient to make I/O channels to block and wait for something
to happen rather than poll at regular intervals, we want I/O to be handled
in separate threads. These can communicate in a threasafe way with the main,
GUI-oriented process through one or several queues. In this solution the GUI
still has to make a poll at a reasonable interval, to check if there is
something in the queue that needs processing. Other solutions are possible,
@stephenmm
stephenmm / gist:9520787
Last active August 29, 2015 13:57
Interactively play with data in matplotlib!!!
# Interactively play with data in matplotlib!!!
# Start python command line:
# > python
# >>>
# Then copy and paste the code below.
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np