Skip to content

Instantly share code, notes, and snippets.

@AlexKalinin
AlexKalinin / OpenWithSublimeText3.bat
Created January 6, 2016 08:09 — forked from roundand/OpenWithSublimeText3.bat
Open folders and files with Sublime Text 3 from windows explorer context menu (tested in Windows 7)
@echo off
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
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
@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
@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 / 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 / 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 --author=login.hedin@gmail.com --oneline master..#{branch}`
commits = data.split("\n").map { |s| s.scan(/\w+ /).first.strip }
patch = ''
@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 / 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 / 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
*/
$ cd ~/.ssh/
$ touch config
$ subl -a config
Then added
#activehacker account
Host github.com-activehacker
HostName github.com
User git