Skip to content

Instantly share code, notes, and snippets.

View grapefroot's full-sized avatar
😰
Working from home

Dmitry Salnikov grapefroot

😰
Working from home
View GitHub Profile
from IPython.display import display
from JSAnimation.IPython_display import display_animation
from matplotlib import animation
def run_env_steps(env, num_steps=1000):
env.reset()
frames = []
for _ in range(num_steps):
# Render into buffer.
# You will still see the window.
@grapefroot
grapefroot / maxSubArray.py
Created June 4, 2015 17:39
Max sum of contiguous subarray
#based on idea that none of the prefixes of
#maximal sum array can be negative(interesting, isn't it)
def maxSubArray(self, A):
cursum = 0
maxsum = -999999999999
for item in A:
cursum += item
maxsum = max(cursum, maxsum)
if cursum < 0:
cursum = 0
# 1 "chia.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "chia.c"
# 49 "chia.c"
int N=0,_,O=328,l=192,y=4,Y[80][64]={0},I;struct LameJavaApp
{
@grapefroot
grapefroot / torchinstall
Created July 18, 2015 18:54
Torch installation script
curl -sk https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; ./install.sh
su-
apt-get install cabal-install && clementine
cabal install xmonad && xmobar --flags="all_extensions"
@grapefroot
grapefroot / xgb.py
Created April 21, 2015 21:49
XGboost usage example
param = {}
param['booster'] = 'gbtree'
param['objective'] = 'multi:softprob'
param['eval_metric'] = 'mlogloss'
param['num_class'] = 9
param['silent'] = 1
param['nthread'] = 1
num_round = 5000
plst = list(param.items())
@grapefroot
grapefroot / frequences.fsx
Created April 4, 2015 12:05
calculate character relevance based on some metric.
open System
open System.IO
open Microsoft.FSharp.Core
let ReadLines fn =
seq { use inp = File.OpenText fn in
while not(inp.EndOfStream) do
yield(inp.ReadLine())
}
@grapefroot
grapefroot / 232.cpp
Created April 3, 2015 07:14
acmp 232
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
struct pt {
double x, y;
pt operator- (pt p) {
@grapefroot
grapefroot / jdk-install
Created March 26, 2015 20:02
intuitive jdk installation
su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java8-installer
exit
import Data.List
maximum' :: (Ord a) => [a] -> a
maximum' [] = error "maximum of empty list"
maximum' [x] = x
maximum' (x:xs) = max x (maximum' xs)
replicate' :: (Num i, Ord i) => i -> a -> [a]
replicate' n x
| n <= 0 = []