Skip to content

Instantly share code, notes, and snippets.

View aratak's full-sized avatar
💾
Uncaught TypeError: [object Object] is not a function

Alexey Osipenko aratak

💾
Uncaught TypeError: [object Object] is not a function
View GitHub Profile
@aratak
aratak / checkbox-label-active.coffee
Created June 16, 2014 15:07
checkbox-label-active.coffee
$(document).on 'click', 'input[type=checkbox]', ->
$("label[for=#{$(@).attr('id')}]").toggleClass 'checkbox-checked', $(@).is(':checked')
@aratak
aratak / array_wrap.rb
Created March 24, 2014 15:47
Array wrap
# config/initializers/array_wrap.rb
class Array
def self.wrap(object)
if object.nil?
[]
elsif object.respond_to?(:to_ary)
object.to_ary || [object]
else
[object]
@aratak
aratak / perfect.coffee
Created March 3, 2014 21:16
perfect number
isDivider = (n, d)-> n % d is 0
maxDivider = (i)-> parseInt(Math.sqrt(i))
sumOfDividers = (n)->
sum = 1;
i = 2
while i <= maxDivider(n)
if isDivider(n, i)
sum += i
@aratak
aratak / ajax_finish_step.rb
Created August 23, 2013 12:52
When I wait for the ajax request to finish
When /^I wait for the ajax request to finish$/ do
until page.evaluate_script('jQuery.isReady&&jQuery.active==0') do
sleep 0.05
end
end
@aratak
aratak / notches_rounding.rb
Created August 20, 2013 11:47
notches_rounding.rb
class Float
def notches_rounding(notches=2)
rounded = (self * notches).round / notches.to_f
rounded % 1 == 0 ? rounded.to_i : rounded
end
end unless Float.respond_to? :notches_rounding
@aratak
aratak / gitconfig
Created August 19, 2013 06:11
git aliases
[alias]
di = diff
dc = diff --cached
amend = commit --amend
aa = add --all
head = !git l -1
h = !git head
r = !git --no-pager l -20
ra = !git r --all
ff = merge --ff-only
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace drawwell
{
class Program
{
@aratak
aratak / 500.js
Created August 10, 2012 08:13
ajax exceptions
$.ajaxSetup
statusCode:
401: -> $.pub('flash:show', text: "You have been logged out. Please, <a href='javascript:window.location.reload()'><span class='icon'>X</span>refresh</a> the page", type: 'warning', hide: false)
404: -> $.pub('flash:show', text: "Page not found", type: 'warning', hide: false)
500: -> $.pub('flash:show', text: "Oops! Something went wrong.", type: 'warning', hide: false)
error: -> $.pub('flash:show', text: "Can't connect to the server. Please, check your internet connection.", type: 'warning', hide: false)
timeout: -> $.pub('flash:show', text: "Server is not response. Please, <a href='http://turbinehq.com/contact/'>report about that to us</a>.", type: 'warning', hide: false)
@aratak
aratak / launchpad_cleaning.sh
Created April 17, 2012 18:19
Launchpad cleaning
#!/bin/sh
sqlite3 ~/Library/Application\ Support/Dock/*.db 'DELETE from apps; DELETE from groups WHERE title<>""; DELETE from items WHERE rowid>2;' && killall Dock
require File.expand_path(File.join(File.dirname(__FILE__), 'config', 'environment'))
if File.exist?('config/database.yml')
database_platform = YAML.load_file(File.join("config/database.yml"))[Rails.env]
database_platform.delete("socket")
ActiveRecord::Base.establish_connection(database_platform)
ActiveRecord::Base.connection.execute("ALTER DATABASE `#{database_platform['database']}` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci\;")
ActiveRecord::Base.connection.tables.each {|table|ActiveRecord::Base.connection.execute("ALTER TABLE `#{table}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci\;")}
puts "Successfully converting database collation"
else