Skip to content

Instantly share code, notes, and snippets.

View pavlov99's full-sized avatar
:shipit:
Coding mode

Kirill Pavlov pavlov99

:shipit:
Coding mode
View GitHub Profile
@pavlov99
pavlov99 / dump-xgboost-trees.py
Created November 2, 2016 03:20
Dump xgboost trees visualisation to the file system in pdf format.
model = xgb.Booster(model_file='your.model')
model.feature_names = xgtrain.feature_names # Note: xgtrain is your train file with features.
model.feature_types = xgtrain.feature_types
# Number of trees in the model
num_trees = len(model.get_dump())
# dump all of the trees to tree folder
for tree_index in range(num_trees):
dot = xgb.to_graphviz(model, num_trees=tree_index)
@pavlov99
pavlov99 / mongo-dump-csv.sh
Last active September 7, 2018 07:23 — forked from mderazon/mongo-dump-csv.sh
Export all of Mongodb collections as csv without the need to specify fields
OIFS=$IFS;
IFS=",";
# fill in your details here
dbname=DBNAME
user=USERNAME
pass=PASSWORD
host=HOSTNAME:PORT
# first get all collections in the database
@karpathy
karpathy / min-char-rnn.py
Last active April 23, 2024 17:55
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@pavlov99
pavlov99 / deque.awk
Last active July 1, 2023 00:16
AWK data structures
function deque_init(d) {d["+"] = d["-"] = 0}
function deque_is_empty(d) {return d["+"] == d["-"]}
function deque_push_back(d, val) {d[d["+"]++] = val}
function deque_push_front(d, val) {d[--d["-"]] = val}
function deque_back(d) {return d[d["+"] - 1]}
function deque_front(d) {return d[d["-"]]}
function deque_pop_back(d) {if(deque_is_empty(d)) {return NULL} else {i = --d["+"]; x = d[i]; delete d[i]; return x}}
function deque_pop_front(d) {if(deque_is_empty(d)) {return NULL} else {i = d["-"]++; x = d[i]; delete d[i]; return x}}
function deque_print(d){x="["; for (i=d["-"]; i<d["+"] - 1; i++) x = x d[i]", "; print x d[d["+"] - 1]"]; size: "d["+"] - d["-"] " [" d["-"] ", " d["+"] ")"}
@pavlov99
pavlov99 / README.txt
Last active August 29, 2015 14:17
Countries with their timezones.
List of currenies is generated using python.
Dependencies
============
pip install pycountry pytz requests

Font Face

A mixin for writing @font-face rules in SASS.

Usage

Create a font face rule. Embedded OpenType, WOFF2, WOFF, TrueType, and SVG files are automatically sourced.

@include font-face(Samplino, fonts/Samplino);
@domenic
domenic / interop.md
Last active July 7, 2022 19:47
`module.exports =` and ES6 Module Interop in Node.js

module.exports = and ES6 Module Interop in Node.js

The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:

  • How can authors of function-modules convert to ES6 export syntax, without breaking consumers that do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.

This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.

@dholbrook
dholbrook / Tree.scala
Created June 21, 2012 17:59
Scala binary tree
/**
* D Holbrook
*
* Code Club: PO1
*
* (*) Define a binary tree data structure and related fundamental operations.
*
* Use whichever language features are the best fit (this will depend on the language you have selected). The following operations should be supported:
*
* Constructors
@jrudolph
jrudolph / Ordering.scala
Created June 29, 2011 13:53
Custom Orderings
sealed abstract class Bound[+T] { val value : T }
case class Closed[T : Ordering](value : T) extends Bound[T]
case class Opened[T : Ordering](value : T) extends Bound[T]
object Bound {
implicit def ordering[T: Ordering]: Ordering[Bound[T]] = Ordering.by((_: Bound[T]).value)
}
object BoundDemo {
def main(args : Array[String]) : Unit = {