Skip to content

Instantly share code, notes, and snippets.

View miry's full-sized avatar

Michael Nikitochkin miry

View GitHub Profile
@miry
miry / md_to_html.html
Created May 1, 2013 19:47
Tested RDiscount parser to convert code blocks without indents.
....
<h2>Installation</h2>
<p>OK. First, you need a running <em>Elasticsearch</em> server. Thankfully, it's easy. Let's define easy:</p>
<pre><code>$ curl -k -L -o elasticsearch-0.20.2.tar.gz http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.2.tar.gz
$ tar -zxvf elasticsearch-0.20.2.tar.gz
$ ./elasticsearch-0.20.2/bin/elasticsearch -f
</code></pre>
@miry
miry / index.html
Created April 23, 2013 20:42
This is a simple Sinatra application with sample of cross domain sharing resource.
<html>
<head>
<title>
Demo Cross Domain
</title>
<!-- Le styles -->
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<style>
body {
[github]
user = miry
[user]
name = Michael Nikitochkin
email = <email>
comment = miry
signingkey = xxxxx
[alias]
require 'benchmark'
n = 50000000
Benchmark.bm(15) do |x|
x.report("regexp1") { 1.upto(n) do ; "XMLHttpReQUEst" =~ /XMLHttpRequest/i; end }
x.report("regexp2") { 1.upto(n) do ; "XMLHttpReQUEst" =~ /xmlhttprequest/i; end }
x.report("downcase") { 1.upto(n) do ; 'XMLHttpReQUEst'.downcase == 'xmlhttprequest'; end }
x.report("strip+downcase") { 1.upto(n) do ; ' XMLHttpReQUEst '.strip!.downcase! == 'xmlhttprequest'; end }
end
def max_overshoot(task_table)
@cache_result ||= {}
result = @cache_result[task_table]
return result if result
prev = 0
prev = max_overshoot(task_table[0..-2]) if task_table.size > 1
total_duration = task_table.reduce(0) {|i, s| i+s[:duration]}
def pairs(numbers, diff)
counter = 0
numbers.sort!
n = numbers.length
numbers.each_with_index do |val, i|
j = i + 1
subject = val + diff
j += 1 while j < n && numbers[j] < subject
while numbers[j] == subject
@miry
miry / quick_sort.rb
Last active December 14, 2015 06:29
def partition(ar)
p = ar[0]
i = 1
j = ar.size - 1
while i<j
i+=1 while i < j && ar[i]<p
j-=1 while j>=i && ar[j]>p
swap(ar,i,j) if i < j
end
def insertionSort(ar)
j = 1
while j < ar.size
i = j - 1
key = ar[j]
while i >= 0 && key < ar[i]
ar[i+1]=ar[i]
puts ar.join(" ")
i -= 1
end
@miry
miry / setup.rb
Created February 20, 2013 07:33
Elasticsearch settings for models with one index
module TireSearch
class Setup
class << self
def settings_options
{
number_of_shards: 1,
number_of_replicas: 0,
analysis: {
char_filter: {
@miry
miry / json_custom.plugin.zsh
Last active December 13, 2015 18:58
This is oh my zsh plugin to work with json
alias pp_json='ruby -e "require \"json\"; require \"yaml\"; puts JSON.parse(STDIN.read).to_yaml"'