Skip to content

Instantly share code, notes, and snippets.

View meltingice's full-sized avatar

Ryan LeFevre meltingice

View GitHub Profile
@meltingice
meltingice / gist:bbf55db4d2ec2d10866f
Created May 6, 2014 15:28
Best way to set class level data and access from instance?
class MyClass < Base
option 'value'
def some_method
puts option
end
end
module Async
def async(method)
prepend(Module.new {
define_method(method) do |*args|
Thread.new(*args) do |*args|
puts Thread.current.object_id.to_s(16)
super(*args)
end
end
})
@meltingice
meltingice / gist:ea3547c0023321786b7a
Created May 15, 2014 13:40
Ruby: Initializing class instance variables with default values for all subclasses
class ParentClass
@foo = "bar"
class << self
attr_accessor :foo
def inherited(subclass)
subclass.instance_variable_set :@foo, "bar"
super
end
class Object
def self.inherited(subclass)
subclass.send(:prepend, Module.new do
def inspect
"naw bawg"
end
end)
super
end
end
9/16/14 9:48:24.752 AM Sonos[20995]: (SCLib) msrch(0): Failed to setup MSearchNotifyHandler.
9/16/14 9:48:24.753 AM Sonos[20995]: (SCLib) msrch(1): Expect self m-search
10/15/14 2:41:17.987 PM Sonos[80437]: (SCLib) msrch(1): Expect self m-search
10/15/14 2:41:17.987 PM Sonos[80437]: (SCLib) msrch(0): Failed to setup MSearchNotifyHandler.

Keybase proof

I hereby claim:

  • I am meltingice on github.
  • I am ryanlefevre (https://keybase.io/ryanlefevre) on keybase.
  • I have a public key whose fingerprint is BEA0 C90A 92D1 C161 2ED8 4DF4 BDEC 0849 9B28 19A8

To claim this, I am signing this object:

/*
* this.getTextSelection()
* Utility function that returns the text that is selected
* and is cross-browser compatible.
*/
OsimoEditorControls.prototype.getTextSelection = function(){
var textarea = $('#'+this.input+'_editbox').get(0);
if (window.getSelection) {
var len = textarea.value.length;
var start = textarea.selectionStart;
var that = this;
Overlay = {
init: function(elementToOverlay, content, options) {
that.options = $.extend({
element: 'div',
attributes: {}
}, options);
that.overlay = $(html[that.options.element](that.options.attributes, content))
.click(that.hideOverlay)
<%% using(common) %%>
<%% common/header() %%>
page content
<%% common/footer() %%>