Skip to content

Instantly share code, notes, and snippets.

View lcapaldo's full-sized avatar

Logan Capaldo lcapaldo

View GitHub Profile
@lcapaldo
lcapaldo / vhxenq.pl
Created September 19, 2011 00:14
Irssi script for automatically queueing video links to VHX.tv
use strict;
use Irssi;
use URI::Find::Rule;
use REST::Client;
use URI::Escape;
use vars qw($VERSION %IRSSI);
$VERSION = '0.01';
%IRSSI = (
@lcapaldo
lcapaldo / Say.cpp
Created October 24, 2011 05:23
Say tool (text to speech on the command line using SAPI)
#include <windows.h>
#include <sapi.h>
int wmain(int argc, wchar_t** argv)
{
ISpVoice *pVoice;
CoInitialize(0);
CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_PPV_ARGS( &pVoice ) );
@lcapaldo
lcapaldo / woah.cpp
Created October 24, 2011 05:25
Mu (Type-level fixpoint combinator) in C++
#include <vector>
#include <iostream>
template<template<typename Q> class T>
struct Mu {
T<Mu<T> > In;
};
template<typename T>
struct Ptr {
@lcapaldo
lcapaldo / lonelyblog.rb
Created November 13, 2011 22:57
My second shoe for two shoes weekend 2: the shoesening
Shoes.app do
@log = []
@entries = stack do
@entry = edit_line
flow do
button("Add text") {
@log << "TXT #{@entry.text}"
@entries.append { title @entry.text }
}
struct at_scope_exit : private std::function<void()> {
at_scope_exit(std::function<void()> do_this) : std::function<void()>(do_this)
{}
~at_scope_exit()
{
(*this)();
}
};
class resource {
mutex m_;
condition_variable cv_;
public:
resource() {}
void with_do(std::function<void()> body)
{
m_.lock();
at_scope_exit u( [&]() { cv_.notify_all(); m_.unlock(); } );
struct counter : resource { int c; } r;
r.with_do([&]()
{
r.c += 1;
r.with_do([&]() { r.c += 1; });
});
r.with_do([&]()
{
r.c += 1;
counter& shadow = r;
r.with_do([&]() { shadow.c += 1; });
});
auto incr = [&]() { r.c += 1; };
r.with_do([&]()
{
r.c += 1;
r.with_do(incr);
});
class resource {
recursive_mutex m_;
condition_variable cv_;
public:
resource() {}
void with_do(std::function<void()> body)
{
m_.lock();
at_scope_exit u( [&]() { cv_.notify_all(); m_.unlock(); } );