Skip to content

Instantly share code, notes, and snippets.

@piotrze
piotrze / named_params.rb
Created November 19, 2015 21:12
ruby named params
def foo(a:, b:, c:)
puts "a: #{a}, b: #{b}, c: #{c}"
end
foo(a: 1, c: 3, b: 2) # a: 1, b: 2, c: 3
#or with hash
params = {a: 1, b: 2, c: 3}
@piotrze
piotrze / custom_fields.rb
Created September 19, 2015 09:37
Little refactor
class CustomFields
def initialize
@hash = {}
end
def []=(key, value)
@hash[key] = value
end
def to_hash
@piotrze
piotrze / usage.coffee
Last active September 19, 2015 08:45
Emulate video tag api, for testing in phantomjs
React.createClass(
componentDidMount: ->
video = @getVideoElement()
video.addEventListener "ended", @ended, false
video.addEventListener "durationchange", @durationChange, false
video.addEventListener "timeupdate", @timeUpdate, false
video.play()
@piotrze
piotrze / find_unused_methods_ruby_on_rails.rb
Last active August 29, 2015 14:22
Find unused methods in your ruby (ruby on rails) projects
#!/usr/bin/env ruby
skip_methods = %w(new create edit update destroy index show initialize to_s call as_json page per_page build up down change)
output = `grep -hr "^\s*def\s" app/`
methods = output.split("\n")
puts "Found #{methods.size} methods."
unused_methods = []
methods.each_with_index do |line, i|
@piotrze
piotrze / default.rb
Last active September 6, 2016 11:23
Setup CORS on engineyard for font files(fontawesome)
#nginx_cors/recipes/default.rb
#create new directory in cookbooks/ in your ey-cloud-recipes repository
#upload recipie, apply and restart nginx on all servers
#
# Cookbook Name:: nginx_cors
# Recipe:: default
#
if ['app_master', 'app', 'solo'].include?(node[:instance_role])
@piotrze
piotrze / application_controller.rb
Created September 25, 2014 08:41
Count number of objects created per request
#app/controllers/application_controller.rb
around_filter :log_objects_creation
protected
def log_objects_creation
@piotrze
piotrze / Brocfile.js
Created August 27, 2014 13:44
Install ember-leaflet to use with ember-cli
//bower install --save ember-cli-leaflet
//bower install --save ember-cli-ember-leaflet
//bower install --save fontawesome
//bower install --save Leaflet.awesome-markers
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var mergeTrees = require('broccoli-merge-trees');
var pickFiles = require('broccoli-static-compiler');
@piotrze
piotrze / success_signup_test.coffee
Last active August 29, 2015 14:05
Emberjs - test foucusOut [success]
Ember.Test.registerAsyncHelper 'leaveBusinessName',
(app, name, context) ->
triggerEvent('input[name="businessName"]', 'blur')
test 'Signup form', ->
click('input[name="businessName"]')
fillIn('input[name="businessName"]', "Some name")
leaveBusinessName()
andThen ->
ok(find("div.businessName span.help-block.error").is(':visible'), "Should see error message on previous field")
@piotrze
piotrze / fail_signup_test.coffee
Last active August 29, 2015 14:05
Emberjs integration test - focusOut [fail]
test 'Signup form', ->
click('input[name="businessName"]')
fillIn('input[name="businessName"]', "Some name")
click('input[name="contactName"]')
andThen ->
ok(find("div.businessName span.help-block.error").is(':visible'), "Should see error message on previous field")
@piotrze
piotrze / initializer.js.coffee
Last active December 19, 2015 16:59
Track user actions.
#ugly code
window.SpaAppActivity = []
window.SpaAppErrorsCount = 0
if window.RailsEnv != 'development' && window.RailsEnv != 'test'
Ember.onerror = (error) ->
console.log(error.stack)
console.log(error.message)
if window.SpaAppErrorsCount < 2