Skip to content

Instantly share code, notes, and snippets.

View aermolaev's full-sized avatar
:octocat:

Alexander Ermolaev aermolaev

:octocat:
  • Moscow
  • 07:22 (UTC +03:00)
View GitHub Profile
function dataURLToBlob(dataURL) {
var BASE64_MARKER = ';base64,';
if (dataURL.indexOf(BASE64_MARKER) == -1) {
var parts = dataURL.split(',');
var contentType = parts[0].split(':')[1];
var raw = decodeURIComponent(parts[1]);
return new Blob([raw], {type: contentType});
}
/* Load Zepto as module */
module.exports = {
entry: "./app.js",
output: {
path: __dirname,
filename: "bundle.js"
},
module: {
loaders: [
{ test: /zepto(\.min)?\.js$/, loader: "exports?Zepto; delete window.$; delete window.Zepto;" },
@aermolaev
aermolaev / gist:a14dbff2e11a81eb2f0a
Last active August 29, 2015 14:10
Chrome: create shortcut
/*
manifest.json:
"permissions": [
"management"
]
*/
var link = document.createElement('a');
link.appendChild(document.createTextNode('Create Yandex shortcut'));
document.body.appendChild(link);
@aermolaev
aermolaev / kill-frozen-passenger-instances
Created December 4, 2010 00:45
Inspecting Phusion Passenger's status and killing frozen apps
#!/usr/bin/ruby -w
# for passenger 3.0
#
# cron
# */15 * * * * root /root/bin/kill-frozen-passenger-instances
require 'rubygems'
require 'net/http'
require 'uri'
@aermolaev
aermolaev / ferret_pagination.rb
Created September 30, 2010 13:39
paginate_search в ferret
module ActsAsFerret
class SearchResults
# To prevent WillPaginate warning
attr_reader :total_pages
end
module ClassMethods
def paginate_search(query, options = {}, find_options = {})
page, per_page = wp_parse_options(options)
offset = (page.to_i - 1) * per_page
@aermolaev
aermolaev / gist:604578
Created September 30, 2010 13:36
WillPaginate
module WillPaginate
module ViewHelpers
# Настройки WillPaginate
pagination_options[:class] = 'g-pager'
pagination_options[:previous_label] = '← предыдущая'
pagination_options[:next_label] = 'следующая →'
# Поддержка TableView
def will_paginate_with_table_view(collection = nil, options = {})
collection = collection.data if TableView === collection
@aermolaev
aermolaev / gist:604577
Created September 30, 2010 13:35
Преобразует PDF-документ в текст
# Преобразует PDF-документ в текст
def attachment2text(attach)
content = ''
if attach.content_type == 'application/pdf'
command = "pdftotext -q -eol unix -enc UTF-8 -nopgbrk \"#{attach.full_filename}\" -"
content = `#{command}`
end
content
@aermolaev
aermolaev / ferret_russian_stemming_analyzer.rb
Created September 30, 2010 13:33
RussianStemmingAnalyzer
class RussianStemmingAnalyzer < Ferret::Analysis::Analyzer
include Ferret::Analysis
include ActionView::Helpers::SanitizeHelper
def initialize(stop_words = FULL_RUSSIAN_STOP_WORDS)
@stop_words = stop_words
@full_sanitizer = HTML::FullSanitizer.new
end
def token_stream(field, str)