Skip to content

Instantly share code, notes, and snippets.

Leonid Shevtsov leonid-shevtsov

Block or report user

Report or block leonid-shevtsov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Toggle.tsx
import * as React from 'react';
export type ToggleChildProps = {
toggle: () => void;
type WithToggleChildProps<P extends object> = ToggleChildProps &
Pick<P, Exclude<keyof P, 'viewComponent' | 'editComponent'>>;
type ToggleProps<P extends object> = {
View array_vs_set_performance.rb
require 'set'
require 'benchmark/ips'
Benchmark.ips do |x|
array = (1..50000).to_a
shuffled_array = array.shuffle
set = array.to_set
hash =[false]*50000).to_h"with array") { array.include?(Random.rand(50000)) }"with shuffled array") { shuffled_array.include?(Random.rand(50000)) }
View sorted_chans.go
package main
import (
func sortedChan(inputChans []<-chan int) <-chan int {
outChan := make(chan int)

Code that does not run is code that rots

In Ruby, there is absolutely no guarantee that a method's declared signature will match the call signature. The only practical way to ensure this is to execute the call.

Thus, if you have code that is not covered by unit tests, you rely on manual testing - and production - to check that it even links, let alone does what you expect.

From my experience with explicit typing, it eliminates a huge class of refactoring mistakes, where you forget to update a method or a call signature. In Ruby, instead of explicit typing, we have unit tests.

This, to me, is the big reason to write unit tests in Ruby - not because it's more productive, or makes for better code. Code that verifiably links is reason enough to write them.

# Put in $PATH/git-pr; chmod +x
# Call with `git pr` to open a compare view for the current branch and a pull request from that
# Depends on
hub compare dev..`git rev-parse --abbrev-ref HEAD`
leonid-shevtsov / gist:5903356
Created Jul 1, 2013
Fixed auto-link web search for Markdown Service Tools
View gist:5903356
require 'net/http'
require 'net/https'
require 'openssl'
require 'uri'
def fetch_with_redirect(uri_str, limit = 10)
return nil if limit==0
uri = URI.parse(uri_str)
http =, uri.port)
View WinSpaceKeyboardLayout.ahk
; Switch keyboard layouts with Win+Space on Windows
#Space::PostMessage, 0x50, 2, 0,, A
View output.txt
$ python2.6
(<type 'exceptions.OSError'>, OSError(32, 'Broken pipe'), <traceback object at 0x1096aa950>)
Traceback (most recent call last):
File "", line 9, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/", line 691, in communicate
return self._communicate(input)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/", line 1222, in _communicate
bytes_written = os.write(self.stdin.fileno(), chunk)
OSError: [Errno 32] Broken pipe

Помогите протестировать патч. Срочно. Патч представляет собой бекпорт из Ruby 2.0.0 бага о том, что Ruby неправильно понимает переменные окружения с не-латинским содержимым (грубо говоря), включая и название домашней папки, из-за чего, например, ломается установка гемов.

От вас нужно: виндоус, предпочтительно на виртуалке (за сохранность физической машины ответственности не несу).

  1. Скачиваем пропатченный RubyInstaller 1.9.3

  2. Создаем пользователя с русским именем ("Руби", например)

  3. Устанавливаем из-под него Ruby

You can’t perform that action at this time.