Skip to content

Instantly share code, notes, and snippets.

@sld
sld / gist:1517246
Created December 24, 2011 12:26
Point projection service
get_2d_projection: () ->
data = ""
$.ajax
async: false
dataType: 'json'
url: "http://0.0.0.0:3000/point_projection/calculate_point_screen_projection?x=#{@x}&y=#{@y}&z=#{@z}&a=#{@a}&b=#{@b}&c=#{@c}&central_project=#{@central_project}"
success: (my_data) ->
data = my_data
return data
@sld
sld / gist:1525118
Created December 27, 2011 21:10
Hornetseye motion object bounding
def get_human_with_place(thresholed_frame, start_frame)
components = thresholed_frame.components
mask = components.largest.erode(10).conditional(255, 0)
x = lazy( *start_frame.shape ) {|i,j| i}
y = lazy( *start_frame.shape ) {|i,j| j}
if x.mask(mask).empty? || y.mask(mask).empty?
return start_frame
else
x_range = x.mask(mask).range
y_range = y.mask(mask).range
@sld
sld / product.rb
Created March 13, 2012 12:38 — forked from clemens/product.rb
the query selects all ids from the full branch from the nested set
class Product
define_index do
# ...
has %(
(
SELECT GROUP_CONCAT(IFNULL(parent.`id`, '0') SEPARATOR ',')
FROM `categories` AS node,
`categories` AS parent
WHERE node.`merchant_id` = `products`.`merchant_id` AND
parent.`merchant_id` = `products`.`merchant_id` AND
@sld
sld / binarytree.rb
Created April 4, 2012 17:07 — forked from yuya-takeyama/binarytree.rb
Binary Tree implemented in Ruby.
module BinaryTree
class Node
attr_reader :word, :count, :left, :right
include Enumerable
def initialize(word)
@word, @count = word, 1
end
@sld
sld / gist:2485900
Created April 25, 2012 03:09
Simple erlang process messaging demonstration
-module(lab).
-compile(export_all).
send_message( GetMsg_PID, Message ) ->
GetMsg_PID ! {message, Message},
io:format(lists:concat(["Sending message ", Message, "\n"]), []).
send_message( GetMsg_PID, Message, Queue_PID ) ->
Queue_PID ! {push, Message, "Sending"},
GetMsg_PID ! {message, Message},
@sld
sld / graph_and_ant_colony.rb
Last active October 4, 2015 22:47
Ant Colony Algorithm / Муравьиный алгоритм
# http://habrahabr.ru/post/105302/
# http://www.machinelearning.ru/wiki/index.php?title=%D0%9C%D1%83%D1%80%D0%B0%D0%B2%D1%8C%D0%B8%D0%BD%D1%8B%D0%B5_%D0%B0%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D1%8B
# http://myprograms.3dn.ru/load
# http://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms
require 'set'
require 'graphviz'
class Node
attr_accessor :name
@sld
sld / backpropogation.rb
Created May 21, 2012 14:15
Backpropogation algorithm / Алгоритм обратного распространения ошибки
# Backpropogation algorithm
# http://ru.wikipedia.org/wiki/%D0%9C%D0%B5%D1%82%D0%BE%D0%B4_%D0%BE%D0%B1%D1%80%D0%B0%D1%82%D0%BD%D0%BE%D0%B3%D0%BE_%D1%80%D0%B0%D1%81%D0%BF%D1%80%D0%BE%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B5%D0%BD%D0%B8%D1%8F_%D0%BE%D1%88%D0%B8%D0%B1%D0%BA%D0%B8
# http://galaxy.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.html
# http://ai4r.rubyforge.org/neuralNetworks.html
# http://ai4r.rubyforge.org/rdoc/classes/Ai4r/NeuralNetwork/Backpropagation.html
class NeuralNetwork
#[2, 3, 3] - NN with 2 neurons in input layer, 1 hidden layer with 3 neurons and output layer with 3 neurons
#[2, 3, 3, 3] - NN with 2 neurons in input layer, 2 hidden layers with 3 neurons in each and output layer with 3 neurons
attr_accessor :weights, :outputs, :deltas
@sld
sld / gist:3778358
Created September 24, 2012 21:02
Diagonal ( zigzag ) matrix traverse OpenMP example
void print_matrix( int **matrix, int count )
{
for( int i = 0; i < count; i++ )
{
printf("\n");
for( int j = 0; j < count; j++ )
printf(" %d ", matrix[i][j]);
}
printf("\n");
}
@sld
sld / gist:3946994
Created October 24, 2012 16:07
Odd Even Sort with C++ and MPI - Алгоритм чет-нечетной сортировки на C++ и MPI
/* http://www.software.unn.ac.ru/ccam/files/HTML_Version/part4.html */
/* http://en.wikipedia.org/wiki/Odd%E2%80%93even_sort */
/* http://bit.ly/NWfuT6 */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <mpi.h>
const int ROOT_NODE = 0;
mineralka@mineralka-borjomietc/openvpn$ cat server.conf
#################################################
# Sample OpenVPN 2.0 config file for #
# multi-client server. #
# #
# This file is for the server side #
# of a many-clients <-> one-server #
# OpenVPN configuration. #
# #
# OpenVPN also supports #