Skip to content

Instantly share code, notes, and snippets.

View jandudulski's full-sized avatar

Jan Dudulski jandudulski

View GitHub Profile
@jandudulski
jandudulski / README
Created October 20, 2012 19:12 — forked from teamon/README
Custom form models
http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
O rly? Duplikacja atrybutów, duplikacja walidacji, pozdro z walidacja typu uniqueness of albo cokolwiek innego co hituje bazy per model.
@jandudulski
jandudulski / .vimrc
Last active August 10, 2020 10:31
How to configure your editor to automatically strip trailing whitespaces and keep new line at the end of file?
if has("autocmd")
" remove trailing white spaces
autocmd BufWritePre * :%s/\s\+$//e
endif
@jandudulski
jandudulski / circleci.log
Created January 10, 2013 16:25
Broken circle build
Installing therubyracer (0.11.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb
checking for main() in -lpthread... yes
creating Makefile
make
compiling script.cc
compiling handles.cc
-# taka pierda, że aż funkcje jakąś trzeba wywołać /facepalm
= surround '(', ')' do
= value
-# ja pierdole, jak to ssie
= "(#{value})"
-# nawet nie wiem czy to zadziała, bo się pewnie na parsowaniu wyjebie
@jandudulski
jandudulski / partyhttp.rb
Last active December 20, 2015 08:59
WAAAT (httparty and empty body)?!?!
Response.new(self, last_response, lambda{}, {body: ""})
=> nil
Response.new(self, last_response, lambda{}, {body: ""}).nil?
=> true
Response.new(self, last_response, lambda{}, {body: ""}).class
=> HTTParty::Response
Response.new(self, last_response, lambda{}, {body: ""}) == nil
=> false
Response.new(self, last_response, lambda{}, {body: ""}) === nil
=> true
@jandudulski
jandudulski / irb.rb
Created July 29, 2013 13:18
pry vs irb
class Example; def inspect; raise "whatever"; end; end;
Example.new
RuntimeError: whatever
from (irb):1:in `inspect'
from /home/yanoo/.rbenv/versions/1.9.3-p194/bin/irb:12:in `<main>'
Api = ($http) ->
{
games: {
query: ->
$http.get('/games', params: {format: 'json'})
}
}
angular.module('got').factory('Api', ['$http', Api])
@jandudulski
jandudulski / ctrl.coffee
Last active December 22, 2015 09:09
Handling server errors in angular
angular.module('app').controller 'UserCtrl', ($scope, User) ->
$scope.save(user) ->
$scope.errors = {}
success = ->
# do something
error = ->
angular.forEach result.data.errors, (errors, field) ->
$scope.form[field].$setValidity('server', false)
$scope.errors[field] = errors.join(', ') # e.g. username is already taken
@jandudulski
jandudulski / 0_reuse_code.js
Created January 20, 2014 15:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jandudulski
jandudulski / auth.rb
Last active September 14, 2022 12:09
CSRF on Grape
# based on http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
module Auth
extend ActiveSupport::Concern
included do
helpers do
def session
env['rack.session']
end