Skip to content

Instantly share code, notes, and snippets.

View wegorich's full-sized avatar
💩
Crappy codding

Egor Malkevich wegorich

💩
Crappy codding
View GitHub Profile
@wegorich
wegorich / Binding WPF command
Last active December 11, 2015 01:29
Binding WPF command using WPFToolkit.Extended
//xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
//xmlns:toolkit="clr-namespace:Xceed.Wpf.Toolkit;assembly=WPFToolkit.Extended"
<toolkit:WatermarkTextBox Padding="6,4"
TextOptions.TextRenderingMode="Aliased" Watermark="Введите что нибудь для поиска" >
<toolkit:WatermarkTextBox.BorderBrush>
<SolidColorBrush Color="#DDD"/>
</toolkit:WatermarkTextBox.BorderBrush>
<interactivity:Interaction.Triggers>
<interactivity:EventTrigger EventName="TextChanged">
@wegorich
wegorich / erb2haml
Created April 27, 2013 11:35
erb2haml.rake (put to lib/task/ forder) gems required gem 'haml-rails' gem 'html2haml' gem 'hpricot' gem 'ruby_parser'
namespace :erb do
namespace :to do
desc 'Converts all .html.erb files to .html.haml'
task :haml do
print "looking for erb views..\n"
files = `find ./app/views -name *.html.erb`
files.each_line do |file|
file.strip!
print "parsing file: #{file}\n"
`bundle exec html2haml #{file} | cat > #{file.gsub(/\.erb$/, ".haml")}`
@wegorich
wegorich / ransack.ru.yml
Last active December 17, 2015 05:58
ransack locales ru / ransack.ru.yml
ru:
ransack:
search: "Поиск"
predicate: "основное"
and: "и"
or: "или"
any: "любое"
all: "все"
combinator: "комбинатор"
attribute: "аттрибут"
@wegorich
wegorich / fancybox.js.coffe
Created May 13, 2013 14:33
fancybox load html contet
$ ->
$(document).on('click', '.fancybox', (e)->
$.fancybox.showLoading()
$.ajax
url: $(this).attr('href') + type,
success: (data)->
$.fancybox.hideLoading()
$.fancybox(data, {
overlay :
locked : true
@wegorich
wegorich / get file name using jquery for simple file picker
Last active December 21, 2015 12:49
Override default file picker with jquery - show file name after styling
filepicker.on 'change', 'input[type=file]', ()->
$picker=$(this)
$picker.closest('.filename').html($picker.val().replace(/C:\\fakepath\\/i, ''))
@wegorich
wegorich / Show dialogs with fancybox
Created August 23, 2013 08:07
Simple override default dialog box with fancybox
helpers ||= {}
helpers.showMessage = (title, content)->
$.fancybox(['<div class="auth"><div class="block">',
'<h2>',title,'<a href="#" class="btn-close"><i class="icon-remove"></i></a></h2>',
'<div>',content,'</div>',
'</div></div>'].join(''),{
wrapCSS: 'modal'
closeBtn : false
})
@wegorich
wegorich / plural names
Created August 24, 2013 10:33
helpers._plural(n, ['элемент', 'элемента', 'элементов']) - склонения в русском языке
helpers._plural = (n, forms)->
forms[if n%10==1 && n%100!=11 then 0 else if n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) then 1 else 2]
@wegorich
wegorich / _form.haml
Created August 31, 2013 19:09
load avatar from file, url, camera in rails
.avatar-picker
.header
%span.descr
Загрузить фото
%span.radio
= radio_button_tag :option, :file, checked: true
= label_tag :option_file, 'Как файл'
%span.radio
= radio_button_tag :option, :link
= label_tag :option_link, 'Как ссылку'
@wegorich
wegorich / gist:6550669
Created September 13, 2013 13:23
Create hash from active record by field
x.select('moderator, COUNT(*) count').group('moderator').inject({}){|h, o| h[o.moderator=="t"] = o; h }
@wegorich
wegorich / CreateUserAuthorizations
Last active December 23, 2015 02:59
multioauth authorization
class CreateUserAuthorizations < ActiveRecord::Migration
def change
create_table :user_authorizations do |t|
t.string :provider
t.string :uid
t.string :token
t.string :secret
t.hstore :data
t.belongs_to :user
t.boolean :primary, default: false