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
@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 / 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
*/
@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
@AlexKalinin
AlexKalinin / custom_logger.rb
Created November 27, 2017 07:17 — forked from kinopyo/custom_logger.rb
Custom logger file in Rails
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
@AlexKalinin
AlexKalinin / wav_header.h
Created December 23, 2017 06:35 — forked from Jon-Schneider/wav_header.h
C Wav Header Struct
// WAV header spec information:
//https://web.archive.org/web/20140327141505/https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
//http://www.topherlee.com/software/pcm-tut-wavformat.html
typedef struct wav_header {
// RIFF Header
char riff_header[4]; // Contains "RIFF"
int wav_size; // Size of the wav portion of the file, which follows the first 8 bytes. File size - 8
char wave_header[4]; // Contains "WAVE"
@AlexKalinin
AlexKalinin / .gitconfig
Created December 26, 2017 06:04 — forked from rambabusaravanan/.gitconfig
Git Diff and Merge Tool - IntelliJ IDEA
# Linux
# add the following to "~/.gitconfig" file
[merge]
tool = intellij
[mergetool "intellij"]
cmd = /usr/local/bin/idea merge $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")
trustExitCode = true
[diff]
@AlexKalinin
AlexKalinin / index.html
Created September 24, 2018 14:40 — forked from shiawuen/index.html
Sample to upload file by chunk
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>test upload by chunk</title>
</head>
<body>
<input type="file" id="f" />
<script src="script.js"></script>