Skip to content

Instantly share code, notes, and snippets.

@thorn
thorn / paginated_collection.js.coffee
Created May 17, 2012 09:56 — forked from zerowidth/paginated_collection.js
backbone pagination with coffeescript
# coffeescript rules
# Pagination is sticked with model
#
# Server should response in that way:
# {
# articles: [{category_id:null, id:308,…}, {category_id:null, id:307,…}, {category_id:null, id:306,…},…]
# pagination: {total:34, page:2, per_page:15, cat_id:-1, source_id:-1}
# }
# To achieve this controller should look like (using will_paginate gem):
# per_page = params[:per_page].to_i || 15
@thorn
thorn / get_url_params.js.coffee
Created May 23, 2012 13:14
getting url params with coffeescript and jquery
# Returns get parameters.
#
# If the desired param does not exist, null will be returned
#
# To get the document params:
# @example value = $(document).getUrlParam("paramName");
#
# To get the params of a html-attribut (uses src attribute)
# @example value = $('#imgLink').getUrlParam("paramName");
jQuery.fn.extend
@thorn
thorn / set_cursor_positon.js
Created May 23, 2012 15:28
sets cursor position of text areas and fields on selected position
$(function() {
$('textarea').focus().setCursorPosition($('textarea').val().length);
});
$.fn.setCursorPosition = function(pos) {
if ($(this).get(0).setSelectionRange) {
$(this).get(0).setSelectionRange(pos, pos);
} else if ($(this).get(0).createTextRange) {
var range = $(this).get(0).createTextRange();
range.collapse(true);
@thorn
thorn / sort_object_by_key.coffee
Created May 24, 2012 10:07
sorts object by key coffescript
sort_obj_by_key = (obj) ->
sorted = {}
keys = (key for own key, value of obj).sort()
sorted[key] = obj[key] for key in keys
sorted
@thorn
thorn / grouper.rb
Created June 19, 2012 14:32
grouper and unit test
class Grouper
def self.group(list)
result = list.inject([]) do |res, gr1|
current_group = recursive_finder(list, gr1)
res << current_group
end
result | list
end
@thorn
thorn / gist:4350934
Created December 21, 2012 05:55
rc.lua dependencies: vicious library (can be found in awesome-extra Debian/Ubuntu) Ubuntu Mono font netwidget requires name of interface list of programs in autostart secion
-- Standard awesome library
require("awful")
require("awful.autofocus")
require("awful.rules")
-- Theme handling library
require("beautiful")
-- Notification library
require("naughty")
require("vicious")
-- Load Debian menu entries
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click_on('Link Text') # Click either a link or a button
click_on('Button Value')
@thorn
thorn / result.rb
Created January 18, 2016 18:21
Попытка решить простую задачу https://www.facebook.com/aaskerych/posts/1133740353333561
result = 2017.times.inject(Hash.new(0)) do |res, year|
year.to_s.each_char do |char|
res[char] += 1
end
puts "#{year} => #{res}"
res
end
# 0 => {"0"=>1}
# 1 => {"0"=>1, "1"=>1}
@thorn
thorn / Rakefile
Last active January 30, 2016 18:10
Run bundler:audit on every rake task. Source: https://eliotsykes.com/bundler-audit
# File: ./Rakefile
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks
task default: 'bundler:audit'
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFRQA8EBEADrLHxW4807EJMzDjhrR5+FRy5/3616nyLlbWFTLnS1/i514L7Z
LVzbho4eZWjErRWqT1mr+E7dr/c8Ei5J8kUMqm5MoSkCoc5Y7Gp0jKhfDF4Megpd
X2ZKw7VG+4GZU9gxbm+6ymHeDAFRfQjUoHzCZsdsgnhi1C58kMoY39dFidlk24AG
E7y8WEg42yzSyJFjK5+qdGuKTBK4UmYM3uxHbxZgBLZ1PQ9DhsToauTqQSJEFzC+
r4qQeO6CeZAUEhgCt3HnmKE8hdARQelNRICrQc/Gpd3c3Wcpi3zj61cRqTCDBtNJ
h66bN+b6MilfT1S+9YMqLACXIWRcXPPUUWanmleguzGfngRjr/qf2PF6g2HYsp40
4M3CE0JX5O5iD4A81b5duuhIzZhJu1LFyn0uPX/zHlEwo36cQF3ElbsKyX6woXpx
hbHf67y6oQdSivhJvshJamRHxgi+bU6kkiiY0E8L5/8h309TVpd0wXfYfMPeE+V6