Skip to content

Instantly share code, notes, and snippets.

View YuriyGuts's full-sized avatar

Yuriy Guts YuriyGuts

View GitHub Profile
@YuriyGuts
YuriyGuts / git-force-update-all.py
Last active August 29, 2015 14:24
Update all Git repositories in the current folder, undoing all local changes if needed
#!/usr/bin/env python
import os
import subprocess
import sys
confirmation = raw_input("This script may DISCARD YOUR UNCOMMITTED CHANGES. Are you sure (Y/N)? ")
if confirmation.lower() != "y":
sys.exit(1)
@YuriyGuts
YuriyGuts / rdp-connect.sh
Created August 23, 2015 18:07
Connect to a Remote Desktop (RDP) session through TS Gateway on Linux.
#!/usr/bin/env bash
GATEWAY=gateway.company.com
DOMAIN=company.local
RESOLUTION=1920x1080
if [ -z "$1" ]; then
read -p "Computer name (e.g. CP1234): " COMPUTERNAME
else
COMPUTERNAME=$1
@YuriyGuts
YuriyGuts / FindLeavesInFlatNodeArray.cs
Last active December 12, 2015 00:18
A simple 1-pass algorithm for finding leaf nodes in a tree flattened to an array of dot-separated string keys. [C#-flavored pseudocode]
// Precalculate levels according to separator characters.
var nodes = flattenedTree.Select(flatNode => new {
Value = flatNode.Value,
Level = flatNode.Value.Count(c => c == '.'),
IsLeaf = false
}).ToArray();
// Find leaves by comparing the levels of each two adjacent items.
for (int i = 1; i < nodes.Length; i++)
{
@YuriyGuts
YuriyGuts / RandomTreeGenerator.cs
Created February 1, 2013 11:16
Recursively generates a random tree with the specified max depth and sibling count.
private static void PopulateNodeWithRandomSubtree(TreeNode nodeToPopulate, int currentLevel)
{
// These can be the arguments of the function if necessary.
const int maxTreeDepth = 5;
const int maxSiblingCount = 4;
// Generate children for this node if a fair coin toss yields 0 at least QUOTA times,
// where QUOTA increases after each level. That way the deeper it gets, the less will
// be the probability of generating more children.
@YuriyGuts
YuriyGuts / LinqJoinMonadic.cs
Last active December 15, 2015 13:59
Implementation of LINQ's Where, Select and Join extension methods in a monadic way on top of IEnumerable<T>.SelectMany binding function. (an exercise from Eric Lippert's blog post on monads: http://ericlippert.com/2013/03/25/monads-part-ten/)
static class Program
{
static void Main(string[] args)
{
var indices = Enumerable.Range(0, 26);
var alphabet = indices.Select(i => (char)('A' + i));
WriteHeader("WhereMonadic");
foreach (var item in indices.WhereMonadic(item => item % 2 == 0))
{
@YuriyGuts
YuriyGuts / Dump-FileTree.ps1
Created November 3, 2013 19:52
A PowerShell script that dumps the entire file tree of the specified folder(s) and saves the results to a ZIP archive.
<#
.SYNOPSIS
Dumps the entire file tree of the specified folder(s) and saves the results to a ZIP archive.
.PARAMETER SourceFolderList
Path to the folder(s) to retrieve the file tree for. Multiple folders should be separated by the pipe character ("|").
.PARAMETER BackupStorageList
Path to the folder(s) where the ZIP file will be stored. Multiple folders should be separated by the pipe character ("|").
@YuriyGuts
YuriyGuts / titanic-survival-lr.r
Created February 3, 2016 13:11
Predict the survival of RMS Titanic passengers using logistic regression.
# Predict the survival of RMS Titanic passengers using logistic regression.
# Based on Kaggle Titanic dataset: https://www.kaggle.com/c/titanic/data
#
# You might need to install Amelia and ROCR packages.
cleanData <- function(rawData) {
# Uncomment these two lines to visualize the missing data.
# library(Amelia)
# missmap(trainingData, main="Missing vs. observed values")
@YuriyGuts
YuriyGuts / cask-upgrade.sh
Last active June 13, 2016 23:41
Check for updates to all Homebrew Cask applications and upgrade them (workaround until cask gets a built-in mechanism for this)
#!/usr/bin/env bash
fetch() {
echo "Removing brew cache"
local cache=$(brew --cache)
rm -rf "$(brew --cache)"
mkdir "$cache"
mkdir "$cache/Casks"
echo "Running brew update"
brew update
@YuriyGuts
YuriyGuts / cartpole-qlearning.md
Last active October 15, 2016 23:42
An implementation of a cart pole balancing agent using Q-Learning (https://gym.openai.com/evaluations/eval_K41KvF0Re6BJW593cq2Tg).

CartPole Q-Learning Agent

Solves the OpenAI CartPole-v0 environment using a tabular version of Q-Learning with discretized feature space and epsilon-decreasing exploration.

View Repository

@YuriyGuts
YuriyGuts / git-update-all.py
Last active June 12, 2018 13:25
Update all Git repositories in the current folder
#!/usr/bin/env python
"""
Update all Git repos in the current directory. Fast-forward only, no merge commits.
Copyright (c) 2018 Yuriy Guts
usage: git-update-all.py
"""
from __future__ import division, print_function