Skip to content

Instantly share code, notes, and snippets.

;; -*- mode: lisp-interaction -*-
;; http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html
;; P01
(defun my-last (lst)
(if (null lst)
nil
(if (null (cdr lst))
lst
(my-last (cdr lst)))))
@ser1zw
ser1zw / quicksort.c
Created July 5, 2013 17:48
C言語でクイックソートの練習
// -*- mode: c; coding: utf-8 -*-
#include <stdio.h>
void quicksort_internal(int array[], int left, int right, int (*test_func)(int, int)) {
int pivot;
int i, j, tmp;
if (left >= right) {
return;
}
@ser1zw
ser1zw / quicksort.lisp
Created July 5, 2013 17:51
Common Lispでクイックソートの練習
;; -*- mode: lisp; coding: utf-8 -*-
(defun quick-sort(lst &optional (test-func #'<))
(if (<= (length lst) 1)
lst
(let (upper
lower
(pivot (car lst)))
(dolist (v (cdr lst))
(if (funcall test-func v pivot)
@ser1zw
ser1zw / QuickSort.cs
Created July 5, 2013 19:10
C#でクイックソートの練習
using System;
namespace QuickSort
{
class MainClass
{
private static void quickSortInternal<Type>(Type[] array, int left, int right, Func<Type, Type, int> compare)
{
if (left >= right)
{
@ser1zw
ser1zw / find_contours_sample.rb
Created November 5, 2013 16:47
A sample code of CvMat#find_contours to get multiple polygons in an image.
require 'opencv'
# Prepare a sample image (I used an image in this article: http://opencv-srf.blogspot.se/2011/09/object-detection-tracking-using-contours.html)
# $ wget http://4.bp.blogspot.com/-r36OpIdjPWE/UDPMJ2kPFZI/AAAAAAAAAPs/-eO4W_XeDo0/s1600/FindingContours.png
cvMat = OpenCV::CvMat.load('FindingContours.png', 0)
img = cvMat.GRAY2BGR
polygons = []
# CvMat#find_contours returns CvChain when the mode is CV_CHAIN_CODE, or returns CvContour when the mode is one of the others.
#!/usr/bin/env ruby
require "mkmf"
def cv_version_suffix(incdir)
major, minor, subminor = nil, nil, nil
open("#{incdir}/opencv2/core/version.hpp", 'r') { |f|
f.read.lines.each { |line|
major = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_EPOCH|CV_MAJOR_VERSION)\s+(\d+)\s*\Z/
minor = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_MAJOR|CV_MINOR_VERSION)\s+(\d+)\s*\Z/
subminor = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_MINOR|CV_SUBMINOR_VERSION)\s+(\d+)\s*\Z/
#include <iostream>
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
int main(int argc, char *argv[]) {
cv::String faceCascadeFileName = "./cascade.xml";
cv::String windowName = "Face detection";
cv::String imageFileName = "./lenna.png";
require 'opencv'
include OpenCV
w1 = GUI::Window.new("All")
w2 = GUI::Window.new("Removed")
# https://github.com/ruby-opencv/ruby-opencv/blob/master/examples/contours/rotated-boxes.jpg
out1 = CvMat.load("rotated-boxes.jpg", 1)
out2 = out1.clone
gray = out1.BGR2GRAY.threshold(200, 255, :binary)
for f1 in `ls * | sort`; do for f2 in `ls * | grep -v $f1`; do echo $f1 $f2; done; done | awk '{if(TABLE[$1$2]!=1&&TABLE[$2$1]!=1) { TABLE[$1$2]=1; TABLE[$2$1]=1; print $0} }'
@ser1zw
ser1zw / imap-test.go
Created June 2, 2014 12:53
Go IMAP sample
package main
import (
"fmt"
"log"
"os"
"strings"
"time"
"io/ioutil"
"strconv"