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 = array.zip([false]*50000).to_h
x.report("with array") { array.include?(Random.rand(50000)) }
x.report("with shuffled array") { shuffled_array.include?(Random.rand(50000)) }
View sorted_chans.go
package main
import (
"fmt"
"math/rand"
"time"
)
func sortedChan(inputChans []<-chan int) <-chan int {
outChan := make(chan int)
View rotting_code.md

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.

View git-timesheet.sh
#!/bin/sh
# More correct version in ruby: https://gist.github.com/725094
# Instant timesheet - straight from yo git log!
# ...now with commit times as well
git log --committer=`git config --get user.email` --format="%ad %s" --simplify-merges --date=iso --since="1 week ago" --reverse | uniq -w 11 --all-repeated=prepend | sed "s/^\(.\{11\}\)\(.\{5\}\).\{9\}/\1\2/" | sed "s/^$//;ta;s/^.\{11\}//;bend;:a;n;s/ /\\n===========\\n\\n/;:end" |grep -iv "merge branch"
@leonid-shevtsov
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 = Net::HTTP.new(uri.host, uri.port)
View WinSpaceKeyboardLayout.ahk
; Switch keyboard layouts with Win+Space on Windows
#Space::PostMessage, 0x50, 2, 0,, A
View output.txt
$ python2.6 test.py
(<type 'exceptions.OSError'>, OSError(32, 'Broken pipe'), <traceback object at 0x1096aa950>)
Traceback (most recent call last):
File "test.py", line 9, in <module>
lines=sp.communicate(inp)[0]
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 691, in communicate
return self._communicate(input)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1222, in _communicate
bytes_written = os.write(self.stdin.fileno(), chunk)
OSError: [Errno 32] Broken pipe
View ruby-1.9.3-widechar-unicode-patch-test.md

Помогите протестировать патч. Срочно. Патч представляет собой бекпорт из Ruby 2.0.0 бага http://bugs.ruby-lang.org/issues/5570 о том, что Ruby неправильно понимает переменные окружения с не-латинским содержимым (грубо говоря), включая и название домашней папки, из-за чего, например, ломается установка гемов.

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

  1. Скачиваем пропатченный RubyInstaller 1.9.3 https://www.dropbox.com/s/vkx3ia0x1va370l/rubyinstaller-ru.exe

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

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

You can’t perform that action at this time.