Skip to content

Instantly share code, notes, and snippets.

@vicgarcia
vicgarcia / background-subtraction.py
Created December 30, 2015 06:11
demonstration of motion detection with OpenCV
import cv2
import numpy as np
# get the camera
camera = cv2.VideoCapture(1)
# setup output window
cv2.namedWindow('output', cv2.WINDOW_AUTOSIZE)
<?php
$app->get('/sample-page', function() use ($app) {
$cache = new Cache(Kv::getClient());
if (($page = $cache->load('sample-page')) === false) {
$sql = "select * from pages where page_name = 'sample-page'";
$page = Db::doQuery($sql);
$cache->save('sample-page', $page, '3600');
}
<?php
set_include_path(dirname(dirname(__DIR__)));
require 'vendor/autoload.php';
use Slim\Slim;
use SlimProject\Rain;
use SlimProject\Db;
// instantiate the app and view
$app = new Slim(array(
<?php
$app->get('/fixreddit/:subreddit', function($subreddit) use ($app) {
$validSubreddits = [ 'php', 'python', 'programming' ];
if (in_array($subreddit, $validSubreddits)) {
$cache = new Cache(Kv::getClient());
$cacheId = 'fixreddit:' . $subreddit;
<?php
class FixReddit
{
public static function getRSSForSubreddit($subreddit)
{
$feed = new \Suin\RSSWriter\Feed();
$channel = new \Suin\RSSWriter\Channel();
$channel->title("r/$subreddit")
->url("http://reddit.com/r/$subreddit")
<?php
class Cache
{
const KEY_PREFIX = 'cache:';
protected $_client;
public function __construct(\Predis\Client $client)
{
$this->_client = $client;
<?php
class Kv
{
const KEY_PREFIX = 'aSampleApplicationKeyPrefix:';
protected static $_config = null;
public static function getClient()
{
if (!self::$_config) {
" -- / == to left/right thru tabs
map -- gT
map == gt
" ww to save, qq to save + quit, QQ to quit w/o save, zz to toggle fold
map ww :w<CR>
map qq :wq<CR>
map QQ :q!<CR>
map zz za
# add some aliases in ~/.bash_aliases
cat > ~/.bash_aliases << DELIM
alias vim="vim -p"
alias lsg="ls | grep"
alias bin="cd ~/bin"
DELIM
# add PS1 config line to ~/.bashrc
echo "PS1=\"\n\u | \w \"" >> ~/.bashrc
# remap prefix to CTRL-a
set -g prefix C-a
unbind C-b
# unbind tab key to fix autocomplete
unbind-key Tab
# | key splits vertically, _ key splits horizontly
bind \ split-window -h
bind - split-window -v