Skip to content

Instantly share code, notes, and snippets.

@xarimanx
xarimanx / bash.txt
Created April 7, 2014 07:44
appen new line to file
find . -name *.rb | xargs perl -i.orig -pe 'print "# encoding: utf-8\n" if $. == 1; close ARGV if eof'
namespace :db do
namespace :sessions do
desc "Clean up expired Active Record sessions (updated before ENV['UPDATED_AT'], defaults to 1 month ago)."
task :expire => :environment do
time = Time.parse( ENV['UPDATED_AT'] || 1.month.ago.to_s(:db) )
say "cleaning up expired sessions (older than #{time}) ..."
session = ActiveRecord::SessionStore::Session
rows = session.delete_all ["updated_at < ?", time]
say "deleted #{rows} session row(s) - there are #{session.count} session row(s) left"
end
module AlertConfirmer
class << self
def reject_confirm_from &block
handle_js_modal 'confirm', false, &block
end
def accept_confirm_from &block
handle_js_modal 'confirm', true, &block
end
@xarimanx
xarimanx / git_case_sensetive.txt
Created March 24, 2014 14:41
git case sensetive
git config --unset-all core.ignorecase && git config --system core.ignorecase false
@xarimanx
xarimanx / file-uploader.coffee
Created March 21, 2014 10:41
Class for simple remote file uploader
#= require ./index
#= require jquery.fileupload/js/jquery.fileupload
class app.classes.FileUploader
constructor: (@root) ->
@url = jQuery(@root).attr('data-file-upload-path')
@bindings()
@flag = true
@count = 0
bindings: =>
@xarimanx
xarimanx / attr.js
Created March 14, 2014 13:00
return all attr from jq object
(function(old) {
jQuery.fn.attr = function() {
if(arguments.length === 0) {
if(this.length === 0) {
return null;
}
var obj = {};
jQuery.each(this[0].attributes, function() {
if(this.specified) {
@xarimanx
xarimanx / sig_to_img.rb
Created March 4, 2014 07:56
base 64 to Image
def signature_to_img(data, filename)
return if data.blank?
FileUtils.mkdir_p(File.dirname(filename))
instructions = JSON.parse(data).map { |h| "line #{h['mx'].to_i},#{h['my'].to_i} #{h['lx'].to_i},#{h['ly'].to_i}" }.join(' ')
Open3.popen3("convert -size 198x55 xc:transparent -stroke blue -draw @- #{filename}") do |input, output, error|
input.puts instructions
end
end
@xarimanx
xarimanx / get_path.coffee
Created February 25, 2014 09:44
get path
(($) ->
jQuery.fn.getPath = ->
throw "Requires one element." unless @length is 1
path = undefined
node = this
while node.length
realNode = node[0]
name = realNode.localName
break unless name
name = name.toLowerCase()
@xarimanx
xarimanx / assets.rb
Created February 21, 2014 15:37
One more assets path
require "#{Rails.root}/app/models/settings.rb"
config.assets.paths << "#{Rails.root}/app/themes/#{Settings.theme}/assets/stylesheets"
config.assets.paths << "#{Rails.root}/app/themes/#{Settings.theme}/assets/images"
config.assets.paths << "#{Rails.root}/app/themes/#{Settings.theme}/assets/javascripts"
@xarimanx
xarimanx / jq.xpath.js
Created February 21, 2014 06:30
find by xpath
(function($) {
$.xpath = function(exp, ctxt) {
var item, coll = [],
result = document.evaluate(exp, ctxt || document, null, 5, null);
while (item = result.iterateNext())
coll.push(item);
return $(coll);
}