Skip to content

Instantly share code, notes, and snippets.

View miry's full-sized avatar

Michael Nikitochkin miry

View GitHub Profile
@miry
miry / gist:135350
Created June 24, 2009 15:54
Create several associations at once
class User < ActiveRecord::Base
has_many :cars
end
class Car < ActiveRecord::Base
belongs_to :user
end
User.first.cars.build([{}, {}])
@miry
miry / patch-fix-include-jansson-lib.patch
Created June 30, 2011 19:17
Patch to fix issue in cpuminer
From 6cbc591a18d322e40994b50c8bb8161de4f38ca9 Mon Sep 17 00:00:00 2001
From: Michael Nikitochkin <miry.sof@gmail.com>
Date: Sat, 18 Jun 2011 17:48:50 +0300
Subject: [PATCH 166/166] fix includin jansson lib
---
Makefile.am | 8 ++++----
compat/Makefile.am | 8 ++++----
configure.ac | 14 +++++++-------
3 files changed, 15 insertions(+), 15 deletions(-)
@miry
miry / git
Created September 15, 2012 10:50
Zsh function to get issue number
current_branch() {
git_branch=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ $git_branch ]; then
echo "$git_branch"
fi
}
gitissue() {
github_issue=`echo $(current_branch) | sed -e 's/\([0-9]*\).*/\1/'`
if [ $github_issue ]; then
@miry
miry / rb_sprint_burndown.rb.patch
Created November 30, 2012 13:11
Redmine backlogs
diff --git a/app/models/rb_sprint_burndown.rb b/app/models/rb_sprint_burndown.rb
index d505f37..7027656 100644
--- a/app/models/rb_sprint_burndown.rb
+++ b/app/models/rb_sprint_burndown.rb
@@ -43,19 +43,19 @@ class RbSprintBurndown < ActiveRecord::Base
@series ||= {}
key = "#{@direction}_#{remove_empty ? 'filled' : 'all'}"
if @series[key].nil?
- @series[key] = self.burndown[@direction].keys.collect{|k| k.to_s}.sort
+ @series[key] = self.burndown.nil? ? [] : self.burndown[@direction].keys.collect{|k| k.to_s}.sort
@miry
miry / git_custom.plugin.zsh
Last active October 13, 2015 11:27
Custom Zsh plugins
# Git
alias g="git"
# If your branch named like [issue_number]_some_description
gh_issue() {
ghissue=`echo $(current_branch) | sed -e 's/\([0-9]*\).*/\1/'`
if [ $ghissue ]; then
echo "$ghissue"
fi
}
@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"'
@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: {
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 / 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 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