Skip to content

Instantly share code, notes, and snippets.

View olostan's full-sized avatar

Valentyn Shybanov olostan

View GitHub Profile
@olostan
olostan / stringsort.cpp
Created March 17, 2011 21:08
Sort of strings (tiny benchmark)
#include <string>
#include <stdlib.h>
#include <list>
#include <sstream>
using namespace std;
void main(int argc, char **argv)
{
list<string> l;
srand(43242342);
@olostan
olostan / mathproblem.cpp
Created March 25, 2011 20:55
Solution for match problem
#include <sstream>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <vector>
#include <queue>
#include <set>
#include <strings.h>
#include <string.h>
#include <stdlib.h>
@olostan
olostan / pos_pricing.pl
Created March 29, 2011 09:20
Solution for POS Terminal (anti-howto in perl)
use List::Util qw(sum);
use POSIX qw(floor);
# Pricelist
%P = ( "A" => [1.25, 3, 3], "B" => 4.25, "C" => [1,6,5], D=> 0.75 );
# Sale scanning
$_{$_}++ for split (//,qw(ABCDABA));
# Calculate total
@olostan
olostan / simplejcqrs.java
Created April 13, 2011 05:35
Sime CQRS set on java
package simplejcqrs.domain;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import junit.framework.Assert;
import org.junit.Test;
@olostan
olostan / gist:954605
Created May 4, 2011 01:45
fifteen (pure css)
<!DOCTYPE html>
<html>
<head>
<style type="text/css" id="s1" name="s1">
span[class*="row"] {
position: absolute;
width: 25px;
height: 25px;
background: #eee;
padding: 5px;
@olostan
olostan / Program.cs
Created May 24, 2011 13:18
POS terminal problem in 1 line of code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
namespace ConsoleApplication1
{
@olostan
olostan / pos.pl
Created June 7, 2011 09:37
POS Terminal (Perl solution)
use List::Util qw(reduce sum);
use POSIX;
# Pricelist
%P = ( "A" => [1.25, 3, 3], "B" => 4.25, "C" => [1,6,5], D=> 0.75 );
# Sale scanning
map { $_{$_}++ } split (//,qw(ABCDABA));
# Calculate total
@olostan
olostan / pos-functional.js
Created June 7, 2011 11:03
POS terminal (JS solution)
// Helper function:
Object.prototype.objReduce = function (func,initial) { for(x in this) if (this[x]|0==this[x]) initial = func(x,this[x],initial); return initial; };
var pricelist = { A: { price: 1.25, pack: 3, ppack: 3}, B: { price: 4.25 }, C: { price: 1, pack:6,ppack:5}, D: {price: 0.75} }
// Collect array of items into object with fields of items and values of number of selled items.
// Example: A A B => { A: 2, B: 1 }
var collectItems = function(items) {
return items.reduce(function(y,x) { if (y[x]) { y[x]++} else {y[x]=1}; return y;},{});
};
@olostan
olostan / compensate.pl
Created August 21, 2011 21:48
Compensates tranes
sub readfile
{
my $fn = shift;
local $/=undef;
open FILE, $fn or die "Couldn't open file: $!";
$string = <FILE>;
close FILE;
return $string;
}
sub writefile {
@olostan
olostan / dir.js
Created August 22, 2011 13:03
Recursive list of files
var fs = require('fs');
function dir(path, callback) {
var promises = 0;
var all = [];
function _dir(path) {
promises++;
fs.readdir(path, function(err,files) {
promises--;
if (err) throw err;