Skip to content

Instantly share code, notes, and snippets.

@YoukaiCat
YoukaiCat / zadacha.hs
Created April 18, 2012 11:43
Решение простой задачи на различных языках
-- Найти все натуральные числа a,b,c из интервала от 1 до 20,
-- для которых выполняется равенство c2 = b*a2
numbers :: [(Int, Int, Int)]
numbers = [ (a,b,c) | a <- [1..20], b <- [1..20], c <- [1..20], c * 2 == b * a * 2 ]
main :: IO ()
main = mapM_ printParams numbers
where
printParams (a,b,c) = putStrLn $ "a = " ++ show a ++ ", b = " ++ show b ++ ", c = " ++ show c
@YoukaiCat
YoukaiCat / data_module.pas
Created April 18, 2012 12:51
Runtime connection
// Returns a full path to the current dir
function currentDirPath():String;
begin
result:=extractFileDir(expandFileName('anything'));
end;
// Makes connection string at runtime.
// it's necessary because delphi don't understand relative paths.
procedure TDataModule.ADOConnectionBeforeConnect(Sender: TObject);
begin
program zadacha1;
uses Math;
var
x : integer;
function z(x : integer) : real;
var y : real;
begin
@YoukaiCat
YoukaiCat / gist:7664700
Created November 26, 2013 19:34
Ввод строк неопределенного размера.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define BUFF_SIZE 6 /* 5 chars and \0 */
int main()
{
int count = 0;
char temp[BUFF_SIZE];
#!/usr/bin/env ruby
# coding: utf-8
module LCG
def self.generate prev, a, c, m
(a * prev + c) % m
end
end
class LCGBruteForce
@YoukaiCat
YoukaiCat / ItrackerTest.rb
Created April 15, 2016 21:09
ItrackerTest.rb
#!/usr/bin/env ruby
# coding: utf-8
# gem install gnuplot
# Jmeter config: ${__P(threads,1)} and ${__P(rampup,0)}
module OS
require 'rbconfig'
def self.os
@YoukaiCat
YoukaiCat / Dockerfile
Created May 15, 2016 15:50
youkaicat/opendht
FROM debian:latest
MAINTAINER Vladislav Mileshkin "noein93@gmail.com"
RUN apt-get update
RUN apt-get install -y \
libncurses5-dev \
libreadline-dev \
nettle-dev \
libgnutls28-dev \
@YoukaiCat
YoukaiCat / Monad.scala
Last active January 27, 2018 21:53
Monad implementation in Scala
object MonadInterface {
import scala.language.higherKinds
trait Functor[T[_]] {
def map[A, B](f: A => B)(x: T[A]): T[B]
}
trait Applicative[T[_]] extends Functor[T] {
def pure[A](v: A): T[A]
def apply[A, B](f: T[A => B])(a: T[A]): T[B]
@YoukaiCat
YoukaiCat / analyzer.rb
Last active January 27, 2018 21:55
Random Sequence Analysis
class Analyzer
attr_reader :name
def initialize name, numbers, bits_count = 16
@name = name
@numbers = numbers
@bits_count = bits_count
end
# Случайность распределения
@YoukaiCat
YoukaiCat / MoveSemanticsBench.cpp
Last active January 27, 2018 21:56
Move semantics benchmark
#include "MoveSemanticsBench.h"
#include <vector>
#include <algorithm>
#include <memory>
#include <iostream>
#include "Utils.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~