Skip to content

Instantly share code, notes, and snippets.

@AlexKalinin
AlexKalinin / gist:2fe9396620b06a82b3435d068683bc80
Created July 15, 2017 03:09 — forked from bkabrda/gist:2875212
Bundler - prefer local gems
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 236eedd..eb35d3d 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -291,6 +291,10 @@ module Bundler
end
end
+ local = matching_versions.reject { |mv| mv[0].class == Bundler::RemoteSpecification }
+ others = matching_versions - local
$ cd ~/.ssh/
$ touch config
$ subl -a config
Then added
#activehacker account
Host github.com-activehacker
HostName github.com
User git
@AlexKalinin
AlexKalinin / Markdown Table of Contents generator
Created April 23, 2017 12:08 — forked from Tsagadai/Markdown Table of Contents generator
A simple jQuery-based Table of Contents generator
/* A simple jQuery-based Table of Contents generator
* I needed a table of contents for some static markdown pages I created
* with bluecloth and rails (I'll make this a gem yet) and this is the result.
*
* This is one of my first afternoon forays into jQuery so it probably isn't
* the greatest code I've ever written. I have fully annotated the code with
* comments for others to learn and understand. Remove them before use.
*
* Requires jQuery
*/
@AlexKalinin
AlexKalinin / image.rb
Created April 15, 2017 03:09 — forked from seancdavis/image.rb
Rails has_many :through Polymorphic Association (http://goo.gl/lxmehk)
# app/models/image.rb
class Image < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
end
@AlexKalinin
AlexKalinin / decode_trace_complined_js.rb
Created January 27, 2017 12:38
This script helps to decode stacktrace places of concatenated and compiled JS file Raw
class CompiledJsBacktracer
def initialize(trace_arr, path, original_filename, ancor = '/*UNIQ_ANCOR_D6791*/', context_lines = 200)
@trace = trace_arr
@path = path
@original_fname = original_filename
@ancor = ancor
@context_lines = context_lines
end
def process
@AlexKalinin
AlexKalinin / diff-script.rb
Created January 16, 2017 19:31
Diff only current branch to master (even if master was updated after current branch creation)
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'tempfile'
branch = ARGV.first || 'HEAD'
data = `git log --no-merges [email protected] --oneline master..#{branch}`
commits = data.split("\n").map { |s| s.scan(/\w+ /).first.strip }
patch = ''
@AlexKalinin
AlexKalinin / 01_sort.js
Last active November 17, 2016 07:07
Sort of nested array items (or why sql is better :) )
var obj = JSON.parse('[[{"sort_index":0,"value":0,"title":"index"},{"sort_index":1,"value":"ezxczxcst","title":"tags"},{"sort_index":2,"value":"Rhozxczxcda","title":"name"},{"sort_index":3,"value":"Onezxcczxil","title":"lastName"},{"sort_index":4,"value":"A582978zxczxc6d114cb16e52a8959b","title":"passport"},{"sort_index":5,"value":"373 Kensizxcczx ngton Walk, Independence","title":"adress"}],[{"sort_index":0,"value":0,"title":"index"},{"sort_index":1,"value":"vbbest","title":"tags"},{"sort_index":2,"value":"zx Rhoda","title":"name"},{"sort_index":3,"value":"Oneil","title":"lastName"},{"sort_index":4,"value":"A582zxc9786d114cb16e52a8959b","title":"passport"},{"sort_index":5,"value":"373 Kenzxczxcsington Walk, Independence","title":"adress"}],[{"sort_index":0,"value":0,"title":"index"},{"sort_index":1,"value":"zxc zxcest","title":"tags"},{"sort_index":2,"value":"zxczxcRhoda","title":"name"},{"sort_index":3,"value":"Ozxczxcneil","title":"lastName"},{"sort_index":4,"value":"zxczxcA5829786d114cb16e52a8959b","title
@AlexKalinin
AlexKalinin / declOfNum.js
Last active April 10, 2016 08:39 — forked from realmyst/gist:1262561
Склонение числительных в javascript
function declOfNum(number, titles) {
var cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
//usage:
var num = 15;
declOfNum(num, ['товар', 'товара', 'товаров']);
@AlexKalinin
AlexKalinin / db.rake
Created March 2, 2016 08:23 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
class InitMigration < ActiveRecord::Migration
def change
create_table 'pictures', force: :cascade do |t|
t.string 'name', null: false
t.string 'guid', null: false
t.timestamps null: false
end
add_index :pictures, :guid, unique: true