Skip to content

Instantly share code, notes, and snippets.

View jandudulski's full-sized avatar

Jan Dudulski jandudulski

View GitHub Profile
@jandudulski
jandudulski / nginx.conf
Created December 4, 2014 11:02
Faye nginx configuration
location /faye {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
@jandudulski
jandudulski / compile.coffee
Last active August 29, 2015 14:08
Data from directive with custom template
angular.module("app").directive 'box', ($compile) ->
restrict: 'AE'
scope: {}
compile: (elem, attrs) ->
template = elem.html()
(scope, elem, attrs, controller) ->
elem.empty()
elem.append($compile(template)(scope))
@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
@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 / 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
Api = ($http) ->
{
games: {
query: ->
$http.get('/games', params: {format: 'json'})
}
}
angular.module('got').factory('Api', ['$http', Api])
@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>'
@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
-# 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 / 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