Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar
💤

Karol Bucek kares

💤
View GitHub Profile
@ticean
ticean / SVN_Git_Mirror.md
Created January 3, 2012 21:14
SVN Git Mirror

Create Git Mirror from SVN Repository

This guide will demonstrate how to mirror an SVN into a Git repo. You're the target audience if you're an SVN user, just getting started with Git and need to coax your project team over to Git.

The branching scenario has been simplified for clarity.

References

@avdi
avdi / ar-class-methods.rb
Created January 19, 2012 01:08
Confused about class methods on association proxies in AR
class Category < ActiveRecord::Base
belongs_to :sock
def self.foo
relation.build(:name => "bar")
end
end
class Sock < ActiveRecord::Base
has_many :categories
end

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add:

class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@cowboyd
cowboyd / inject_this.rb
Created April 24, 2012 17:01
Injecting an value into a binding
# Is there a better way to inject an arbitrary value into a binding?
def inject_this_as_reference(block, this_object)
eval("lambda {|v| @this = v}", block.binding).call(this_object)
end
def inject_this_as_method(block, this_object)
(class << eval('self', block.binding);self;end).send(:define_method, :this) {this_object}
end
@tobyhede
tobyhede / postsql.sql
Created May 17, 2012 03:08
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- Inspired by
-- http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html
-- http://ssql-pgaustin.herokuapp.com/#1
-- JSON Types need to be mapped into corresponding PG types
--
@nicksieger
nicksieger / gist:2906871
Created June 10, 2012 18:43
Renaming a Java thread in JRuby
$ jirb
irb(main):001:0> t = Thread.new { sleep }
=> #<Thread:0x64e5b2 sleep>
irb(main):002:0> require 'jruby'
=> true
irb(main):003:0> jt = JRuby.reference(t)
=> #<Thread:0x64e5b2 sleep>
irb(main):004:0> jt.native_thread.name
=> "RubyThread-7: (irb):1"
irb(main):005:0> jt.native_thread.name = "My Ruby thread"
require 'socket'
module EventEmitter
def _callbacks
@_callbacks ||= Hash.new { |h, k| h[k] = [] }
end
def on(type, &blk)
_callbacks[type] << blk
self
@josevalim
josevalim / 0_README.md
Created September 13, 2012 21:52
Sinatra like routes in Rails controllers

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.

@letmaik
letmaik / .travis.yml
Last active December 15, 2021 23:10
Deploy snapshots to Sonatype after Travis CI build
language: java
env:
global:
- SONATYPE_USERNAME=yourusername
- secure: "your encrypted SONATYPE_PASSWORD=pass"
after_success:
- python addServer.py
- mvn clean deploy --settings ~/.m2/mySettings.xml