Skip to content

Instantly share code, notes, and snippets.

@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
@meltingice
meltingice / application.rb
Created April 22, 2014 13:15
Add user ID to Rails logs with log tags and Authlogic
MyApp::Application.configure do
config.log_tags = [UserLogger.get]
end
@meltingice
meltingice / metadata.xml
Created December 26, 2013 06:05
Sony DSC-QX10 raw DNLA stream. I believe it transmits image data in JPEG form.
<root xmlns="urn:schemas-upnp-org:device-1-0" xmlns:dlna="urn:schemas-dlna-org:device-1-0" xmlns:av="urn:schemas-sony-com:av">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<dlna:X_DLNADOC xmlns:dlna="urn:schemas-dlna-org:device-1-0">DMS-1.50</dlna:X_DLNADOC>
<deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType>
<friendlyName>DSC-QX10</friendlyName>
<manufacturer>Sony Corporation</manufacturer>
class SomeApp
def some_function(a)
puts a
Views::Index.instance_eval do
attr_reader :a
set_instance_variable(:@a, a)
end
end
class SomeApp
def some_function(a)
puts a
end
module Views
class Index < Mustache
@meltingice
meltingice / csshx.rb
Last active December 25, 2015 13:09
Capistrano recipes for SSHing into multiple servers simultaneously using csshX. Ensures csshX is installed if you're using homebrew on OSX. Add this or load it into your deploy.rb and profit.
namespace :csshx do
task :install do
`which csshx`
if $? != 0
Bundler.with_clean_env do
run_locally 'brew install csshx'
end
end
end
var myClass = {
myMethod: function () {
console.log('foo');
}
};
// These are all equivalent in JS
myClass.myMethod()
myClass['myMethod']()
<head>
<script type="text/javascript">
var ready = false;
var caman = Caman('#example', 'EdielOficial.JPG', function () {
this.render(function () {
ready = true;
//this.save('png'); // shows a download file prompt
});
});
emitterLine: [
{x: 670, y: 170}
{x: 735, y: 370}
]
@meltingice
meltingice / gist:5053848
Created February 28, 2013 03:04
Function to check the existence of a deeply nested object property
function hasProperty() {
var args = Array.prototype.slice.call(arguments, 0);
var obj = args.shift();
var ref = obj;
for (var i = 0, _len = args.length; i < _len; i++) {
if (!ref[args[i]]) return false;
ref = ref[args[i]];
}