Skip to content

Instantly share code, notes, and snippets.

View morr's full-sized avatar
🏠
Working from home

Andrey Sidorov morr

🏠
Working from home
View GitHub Profile
--langdef=js
--langmap=js:.js
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*\{/\5/,object/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*function[ \t]*\(/\5/,function/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*\[/\5/,array/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*[^"]'[^']*/\5/,string/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*(true|false)/\5/,boolean/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*[0-9]+/\5/,number/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*.+([,;=]|$)/\5/,variable/
--regex-js=/(,|(;|^)[ \t]*(var|let|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*[ \t]*([,;]|$)/\5/,variable/
@morr
morr / e.ruby
Created November 5, 2011 12:34
Linux archives unpacker
#!/usr/bin/ruby
# The program e is a command line utility that extracts lots of
# different archives. It is very simple and can be extended very easily.
#
# It is inspired by how firewall use their rulesets, and works like this:
#
# * For each file that has to be extracted, the rules are matched one after the other.
# * When a rule matches (either by the filetype or filename), the command is executed.
# * If the command does not return an error code the extraction is considered successful,
@morr
morr / notify.rb
Created November 5, 2011 12:34
Linux libnotify notifier
#!/usr/bin/ruby
require 'rubygems'
require 'libnotify'
require 'getoptlong'
parser = GetoptLong.new
parser.set_options(["-s", "--summary", GetoptLong::REQUIRED_ARGUMENT],
["-b", "--body", GetoptLong::REQUIRED_ARGUMENT],
["-i", "--icon_path", GetoptLong::REQUIRED_ARGUMENT]
);
@morr
morr / gist:2015619
Created March 11, 2012 08:36
Содержимое ифрейма
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<h2>inner</h2>
<script>
jQuery(function() {
if ('parent' in window && window != window.parent && 'postMessage' in window.parent) {
window.parent.postMessage('page_change:20', '*');
}
});
$(window).bind('message', function(e) {
@morr
morr / iframe_inner.html
Created March 11, 2012 08:36
Схема коммуникаций между доменами
<script src="http://readmanga.ru/js/jquery/jquery-1.4.3.min.js"></script>
<h2>inner</h2>
<script>
function notify_parent(message) {
if ('parent' in window && window != window.parent && 'postMessage' in window.parent) {
window.parent.postMessage(message, '*');
}
}
jQuery(function() {
@morr
morr / gist:2855443
Created June 1, 2012 22:12
cross point
//-----------------------------------------------------------------------------
#include <windows.h>
//-----------------------------------------------------------------------------
//#define __TEST__
//-----------------------------------------------------------------------------
#ifndef __TEST__
#pragma comment(linker,"/MERGE:.rdata=.text")
//#pragma comment(linker,"/FILEALIGN:512 /SECTION:.text,EWRX /IGNORE:4078")
#pragma comment(linker,"/ENTRY:WinMain")
#endif
@morr
morr / gist:2902690
Created June 9, 2012 21:41
gemfile
source 'http://rubygems.org'
group :test, :development do
gem 'debugger'#, :git => 'git://github.com/cldwalker/debugger.git'
#gem 'ruby-debug19', :require =>'ruby-debug'
gem 'rspec-rails'
gem 'capybara', :git => 'git://github.com/jnicklas/capybara.git'
gem 'launchy'
gem 'shoulda'
# encoding: utf-8
class Recommendations::Metrics::MetricBase
# элемент в списке, но без оценки
NotRated = -1
def initialize(klass)
@klass = klass
end
class Recommendations::Metrics::Euclid < Recommendations::Metrics::MetricBase
def compare(user_id, user_rates, sampler_id, sampler_rates)
return 0 unless user_rates && sampler_rates
shared_ids = user_rates.keys & sampler_rates.keys
return 0 if shared_ids.empty?# || shared_ids.size < MinimumShared
# сумма квадратов разницы
sum_of_squares = shared_ids.sum do |id|
(user_rates[id] - sampler_rates[id])**2
end
class Recommendations::Metrics::Pearson < Recommendations::Metrics::MetricBase
def compare(user_id, user_rates, sampler_id, sampler_rates)
return 0 unless user_rates && sampler_rates
shared_ids = user_rates.keys & sampler_rates.keys
return 0 if shared_ids.empty?# || shared_ids.size < MinimumShared
sum1 = sum2 = sum1Sq = sum2Sq = pSum = 0.0
shared_ids.each do |id|
prefs1_item = user_rates[id] || 0.0