Skip to content

Instantly share code, notes, and snippets.

View YuriyGuts's full-sized avatar

Yuriy Guts YuriyGuts

View GitHub Profile
@YuriyGuts
YuriyGuts / kindle-cloud-reader-custom-sepia.js
Last active October 31, 2020 18:28
A bookmarklet for applying a custom style to Kindle Cloud Reader (applies a sepia theme with a higher contrast similar to iBooks on iPad; increases the size of fonts that are too small). Use a tool like http://ted.mielczarek.org/code/mozilla/bookmarklet.html to convert it to a one-liner and use it as a bookmarklet.
function applyCustomStyle() {
var config = {
backgroundColor: "rgb(246, 239, 220)",
foregroundColor: "rgb(64, 41, 25)",
highlightColor: "rgb(255, 245, 173)",
codeFontSize: "12px"
};
var masterFrameContents = $("#KindleReaderIFrame").contents();
var pageFrameContents = masterFrameContents.find("iframe").contents();
@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 / 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 / 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 / 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++)
{