Skip to content

Instantly share code, notes, and snippets.

View alekseyl1992's full-sized avatar

Leontiev Aleksey alekseyl1992

  • MailRu Group
  • Moscow
View GitHub Profile
@alekseyl1992
alekseyl1992 / gist:2de3975f88b009b4e53d
Created June 17, 2014 16:23
Normal distribution from uniform distribution
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <array>
float getVal() {
#include <iostream>
#include <thread>
int main()
{
for (int i = 0; i < 1000; ++i) {
int a = 5;
int b = 5;
int sum = 0;
#include <iostream>
#include <vector>
#include <limits>
#include <assert.h>
size_t solution(const std::vector<double>& data) {
std::vector<double> avgs(data.size(), 0);
size_t l = data.size();
avgs[l - 1] = data[l - 1];
function calcNearest() {
// build queue
var nodeList = _toNodeList(distTable);
var queue = _.sortBy(nodeList, 'value');
// build path
var path = [];
var l = 0;
var idToFind = null;
results = [{
method: 'Метод "Иди в ближний"',
values: [{
path: '1-2-3-4-5-1',
l: 10
}, {
path: '1-3-2-4-5-1',
l: 20
}]
}, {
@alekseyl1992
alekseyl1992 / CustomViewGroup.java
Created May 5, 2015 21:13
Android custom ViewGroup implementation
package com.example.igor.test;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
using Generation = std::vector<Genome>;
constexpr int buildingSize = 100;
Genome createGenome() {
Genome genome;
int currentFloor = 0;
do {
@alekseyl1992
alekseyl1992 / go_tcp_server.go
Last active September 3, 2015 11:57
Go TCP server
package main
import (
"fmt"
"net"
"os"
)
const (
CONN_HOST = "localhost"
@alekseyl1992
alekseyl1992 / two_phase_virtual_invocation.cpp
Created November 12, 2015 09:18
Two phase C++ virtual invocation
#include <exception>
#include <stdexcept>
#include <string>
class NotImplementedException : public std::runtime_error {
public:
NotImplementedException(const std::string& str)
: std::runtime_error(str) {
}
@alekseyl1992
alekseyl1992 / spark_perf_test.py
Created January 20, 2016 12:51
Spark Perf test
import random
def sample(p):
x, y = random.random(), random.random()
return 1 if x*x + y*y < 1 else 0
def run(sc, num_samples):
count = sc.parallelize(xrange(0, num_samples)).map(sample) \
.reduce(lambda a, b: a + b)
print "Pi is roughly %f" % (4.0 * count / num_samples)