Skip to content

Instantly share code, notes, and snippets.

View thekvs's full-sized avatar

Konstantin Sorokin thekvs

View GitHub Profile
@thekvs
thekvs / gist:867561
Created March 12, 2011 21:08
Написать генератор чисел Фибоначчи. Результатом работы генератора должна быть пара {очередное_число, генератор_следующего_числа}.
-module(fib_gen).
-export([generator/0]).
generator() ->
receive
{A, B} ->
NewA = B,
NewB = A + B,
self() ! {NewA, NewB}
after 0 ->
@thekvs
thekvs / cs229_mp4_download_links.txt
Created March 4, 2012 07:29
machine learning cs 229 mp4 download links
@thekvs
thekvs / vtt.cpp
Created January 16, 2013 19:05
Variadic templates example. Compilation tested on GCC 4.7 with $ g++ -Wall -W -std=c++11 vtt.cpp -o vtt
#include <iostream>
// Base of a recursion
void
print()
{
std::cout << std::endl;
}
// Function to print any type without type specifiers
@thekvs
thekvs / primes.R
Created March 13, 2013 17:02
Print all prime numbers less than 1000000
library(gmp)
p <- 1
while (T) {
p <- nextprime(p)
if (p > 1000000) {
break
}
cat(sprintf("%s\n", p))
}
#include <iostream>
#include <limits>
int
main()
{
std::cout << std::numeric_limits<double>::epsilon() << std::endl;
std::cout << std::numeric_limits<float>::epsilon() << std::endl;
return 0;
@thekvs
thekvs / gist:5194368
Created March 19, 2013 07:47
Deduce return type through decltype
// compiles with gcc 4.7+:
// g++ -Wall -W -g -std=c++11 test.cpp -o /tmp/test
//
// ... and clang 3.0+:
// clang++ -W -g -std=c++11 test.cpp -o /tmp/test
#include <iostream>
#include <typeinfo>
template<class T, class U>
auto mul(T x, U y) -> decltype(x*y)
kvs@lair tmp:> cat t.c
#include <stdio.h>
int
main()
{
char *p = "aaa";
if (p = NULL) {
printf("WHAT?\n");
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thekvs
thekvs / t.py
Created November 15, 2015 12:00
select and change values in the data frame using frequency criteria
import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3, 3, 4, 1, 7, 8, 9], 'b': [1, 1, 1, 1, 4, 4, 2, 3, 1]})
print(df)
print("========")
cidx = df.b.value_counts() <= 1
df.loc[df.b.isin(cidx.index[cidx]), 'b'] = 9999
print(df)