Skip to content

Instantly share code, notes, and snippets.

@EyalAr
EyalAr / gist:3018471
Created June 29, 2012 15:03
An explanation + examples about Java generics and bounded wildcards.
/**
* Java Generics, Wildcards and Bounded Wildcards.
*
* ...Can be confusing. Here's a small explanation + examples.
*/
import java.util.LinkedList;
import java.util.List;
/**
@EyalAr
EyalAr / registerS3ProtocolStreamWrapper.php
Last active January 29, 2019 19:31
Registering and using S3 protocol with AWS S3 stream wrapper for PHP
<?php
define('AWS_KEY','YOUR_AWS_KEY_HERE');
define('AWS_SECRET','YOUR_AWS_SECRET_HERE');
require_once('AWSSDKforPHP/sdk.class.php');
require_once('AWSSDKforPHP/extensions/s3streamwrapper.class.php');
$s3 = new AmazonS3(array(
'key' => AWS_KEY,
@EyalAr
EyalAr / hello_world_opencv.cpp
Created October 23, 2012 18:37
Hello World in OpenCV
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main(int argc, char** argv) {
//create a gui window:
namedWindow("Output",1);
@EyalAr
EyalAr / ExtractEigenfaces.m
Last active August 17, 2017 21:33
Matlab script which extracts to files the eigenfaces of a set of face images.
% Extract the eigen-faces of a set of face images.
start_index = 1;
end_index = 10;
base_name = '';
extension = '.jpg';
in_dir = 'in';
out_dir = 'ef';
images = [];
@EyalAr
EyalAr / InitPersonRecognizer.cpp
Last active December 1, 2016 03:34
Code snippets for my OpenCV face recognition tutorial, in which I show how to build an application which recognizes a specific person in a video. Full code at: https://bitbucket.org/EyalAr/person-recognizer
#define PERSON_LABEL = 10 //some arbitrary label
//LBPH face recognizer parameters:
#define RADIUS 1
#define NEIGHBORS 8
#define GRID_X 8
#define GRID_Y 8
#define THRESHOLD 130.0
//create a LBPH face recognizer model:
@EyalAr
EyalAr / CsvWriter.hpp
Last active December 15, 2015 21:38
Code samples for my face detection and recognition with OpenCV tutorial. http://blog.eyalarubas.com/2013/03/14/face-detection-and-recognition-theory-and-practice/
class CsvWriter {
public:
CsvWriter(const string &csvPath);
virtual ~CsvWriter();
void nextLine();
void addEntry(const string &s);
private:
ofstream _fs;
bool _isFirstEntry;
};
@EyalAr
EyalAr / client.py
Created December 11, 2013 18:17
Demo code for my post about python's blocking stream reading functions.
from subprocess import Popen, PIPE
from time import sleep
# run the shell as a subprocess:
p = Popen(['python', 'shell.py'],
stdin = PIPE, stdout = PIPE, stderr = PIPE, shell = False)
# issue command:
p.stdin.write('command\n')
# let the shell output the result:
sleep(0.1)
@EyalAr
EyalAr / count_words_in_selection.py
Last active July 1, 2021 07:35
Count words in selection - plugin for Sublime Text 3. Full blog post: http://eyalarubas.com/count-words-in-sublime-text-3.html
import sublime, sublime_plugin, re
class CountWordsInSelectionCommand(sublime_plugin.EventListener):
def on_selection_modified(self, view):
'''
listen to event 'on_selection_modified' and count words in all selected
regions when invoked.
'''
@EyalAr
EyalAr / 1.generator_example.js
Created May 9, 2014 07:19
Code snippets for Javascript generators and asynchronous code presentation. Based on http://eyalarubas.com/javascript-generators-and-callbacks.html
// generate a series of even numbers,
// but be able to to reverse the order of iteration
function * generateEvens(start) {
var dir = 1; // up
if (start % 2 !== 0) start++;
while (true) {
var tmp = yield start;
if (tmp === 'up') dir = 1;
if (tmp === 'down') dir = -1;
@EyalAr
EyalAr / batch_export.sh
Last active October 3, 2023 01:55
Shell script to easily export mongo collections into JSON files
#!/usr/bin/env bash
#https://gist.github.com/EyalAr/67791f51fce51ed55594
COLLECTIONS=()
HOST="127.0.0.1"
PORT="27017"
DB=
if [ -n "$1" -a "$1" = "--help" ]