Skip to content

Instantly share code, notes, and snippets.

View trekdemo's full-sized avatar

Gergő Sulymosi trekdemo

View GitHub Profile
@trekdemo
trekdemo / rendering.rb
Last active December 11, 2015 04:58
Override rails 3.0.17 partial rendering to get information about the partial we render
# Override rails 3.0.17 partial rendering to get information
# about the partial we render
# put it into config/initializers/rendering.rb
module ActionView
module Rendering
def _render_partial(options, &block)
"<b style='float:left;' title='h#{CGI::escapeHTML options.inspect.html_safe}'>*</b>".html_safe +
super
end
end
@trekdemo
trekdemo / drop_connections.rake
Created November 13, 2012 13:11
Drop postgres connections to a database in a Rails application
namespace :db do
desc 'Drop all database connections'
task :drop_connections => :environment do
database = Rails::Application.config.database_configuration[RAILS_ENV]["database"]
field = if ActiveRecord::Base.connection.send( :postgresql_version ) < 90200
'pg_stat_activity.procpic' # PostgreSQL <= 9.1.x
else
'pg_stat_activity.pid' # PostgreSQL >= 9.2.x
end
@trekdemo
trekdemo / readability_to_instapaper_html.rb
Created November 4, 2012 19:00
Migrate readability json format to instapaper html format for pocket app import
require 'json'
TEMPLATE = <<-HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Instapaper: Export</title>
</head>
<body>
@trekdemo
trekdemo / relative_model_naming.rb
Created October 3, 2012 15:41
How to get relative model naming in rails before version 3.1
require 'ostruct'
module RelativeModelNaming
def model_name
ActiveModel::Name.new OpenStruct.new( :name => self.name.split( '::' ).last )
end
end
# Example usage:
class Module::Model
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.external.ExternalInterface;
public class Main extends Sprite {
@trekdemo
trekdemo / commitdiff.sh
Created May 2, 2012 11:04 — forked from major/commitdiff.sh
Differences in commits between two branches (on rackerhacker.com)
MASTER=`git log --pretty=format:'%H' master | sort`
DEV=`git log --pretty=format:'%H' development | sort`
for i in `diff <(echo "${MASTER}") <(echo "${DEV}") | grep '^>' | sed 's/^> //'`;
do
git --no-pager log -1 --oneline $i;
done
@trekdemo
trekdemo / flash_player.rb
Created February 3, 2012 14:00 — forked from rjungemann/flash_player.rb
FlexSDK Homebrew formula. Installs mxmlc and other tools.
require 'formula'
class FlashPlayer < Formula
url 'http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.app.zip'
md5 '2770acd6997bfd5016dd51acfb20c025'
homepage 'http://adobe.com'
version '11.1'
def install
name = 'Flash Player Debugger.app'
@trekdemo
trekdemo / permission.json
Created January 16, 2012 10:49
Amazon S3: Public read permission for anybody
{
"Version": "2008-10-17",
"Id": "",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
@trekdemo
trekdemo / policy.json
Created January 10, 2012 10:05
Restrict user access to a specified bucket on Amazon S3
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::*"
@trekdemo
trekdemo / index.html
Created December 11, 2011 09:58
Add application to Page tag
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<a href="#" onclick=window.open("http://www.facebook.com/dialog/pagetab?
app_id=YOUR_APP_ID&next=YOUR_URL","PageTab","width=500,height=200");>
Dialog</a>
</body>
</html>