Skip to content

Instantly share code, notes, and snippets.

View ream88's full-sized avatar

Mario Uher ream88

View GitHub Profile
@ream88
ream88 / x
Created December 3, 2008 12:02
CmdUtils.CreateCommand({
name: "delicious",
homepage: "http://ryan.codecrate.com/",
author: { name: "Ryan Sonnek", email: "ryan@codecrate.com"},
contributors: ["Ryan Sonnek"],
license: "MIT",
description: "Tags the current site using delicious",
icon: "http://delicious.com/favicon.ico",
help: "Save the current url to delicious with the tags input by the user. Any selected text on the page will be recorded as the note.",
/*
=skin=
@name Custom
@author You
@homepage http://www.yourpage.com
@email you@you.com
@license MPL/LGPL/GPL
=/skin=

Usage:

javascript_include_tag('jquery.js', 'app.js', :use_head_loader => true) will result in:

<script src="/javascripts/head.load.min.js?1292496592" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
head.js('/javascripts/jquery.js?1277379629', '/javascripts/app.js?1291631927');
//]]>
@ream88
ream88 / gist:748860
Created December 20, 2010 19:28
Minecraft Client bug after connecting to a Windows 7 Server
20.12.10 20:02:11 [0x0-0x34034].com.Mojang Specifications.Minecraft.Minecraft[873] java.io.EOFException
20.12.10 20:02:11 [0x0-0x34034].com.Mojang Specifications.Minecraft.Minecraft[873] at java.io.DataInputStream.readInt(DataInputStream.java:375)
20.12.10 20:02:11 [0x0-0x34034].com.Mojang Specifications.Minecraft.Minecraft[873] at cn.a(SourceFile:40)
20.12.10 20:02:11 [0x0-0x34034].com.Mojang Specifications.Minecraft.Minecraft[873] at gu.b(SourceFile:100)
20.12.10 20:02:11 [0x0-0x34034].com.Mojang Specifications.Minecraft.Minecraft[873] at ke.c(SourceFile:157)
20.12.10 20:02:11 [0x0-0x34034].com.Mojang Specifications.Minecraft.Minecraft[873] at ke.c(SourceFile:15)
20.12.10 20:02:11 [0x0-0x34034].com.Mojang Specifications.Minecraft.Minecraft[873] at pu.run(SourceFile:68)
20.12.10 20:02:11 [0x0-0x34034].com.Mojang Specifications.Minecraft.Minecraft[873] Player is nf@8d
@ream88
ream88 / _form.html.erb
Created June 7, 2011 14:03
Get STI models working with forms (you can assign the model's type directly)
<%= f.select(:type, ['User', 'Admin']) %>
@ream88
ream88 / changeable.rb
Created June 9, 2011 11:58
Changeable Concern
module Changeable
extend ActiveSupport::Concern
included do
attr_accessible :type
end
module ClassMethods
def new(attributes = nil, options = {}, &block)
type = attributes['type'] if attributes.is_a?(Hash)
@ream88
ream88 / translatable.rb
Created June 9, 2011 11:58
Translatable Concern
module Translatable
extend ActiveSupport::Concern
module InstanceMethods
def method_missing(*args)
method = /(\w+)(.)?/.match(args.first).to_a.last(2)
method = "#{method.first}_#{args.second}#{method.second}"
if respond_to?(method)
send(method)
else
@ream88
ream88 / ostruct.rb
Created June 16, 2011 08:30
Hash to OpenStruct (recursive)
class Hash
def to_ostruct
OpenStruct.new(Hash[*collect do |key, value|
[key, value.is_a?(Hash) ? value.to_ostruct : value]
end.flatten])
end
end
@ream88
ream88 / writeexcel_template_handler.rb
Created July 19, 2011 23:34
writeexcel Template handler (fileextension is .writeexcel) for Rails 3.0
require 'action_dispatch/http/mime_type'
require 'action_view'
require 'writeexcel'
class WriteExcelTemplateHandler < ActionView::TemplateHandler
include ActionView::TemplateHandlers::Compilable
def compile(template)
%{
tmp = Tempfile.new('writeexcel')
@ream88
ream88 / diff.rb
Created August 4, 2011 15:39
Difference between two dates
require 'rubygems'
require 'active_support/all'
time = ("2011-08-12 09:00:00").to_time
def diff(time)
delta = time - Time.now
%w[days hours minutes].collect do |step|
seconds = 1.send(step)
(delta / seconds).to_i.tap do