Skip to content

Instantly share code, notes, and snippets.

@luxerama
luxerama / _form.html
Created March 14, 2012 11:48
Many-to-Many association support with batman.js
<div>
<div data-addclass-error="channel.errors['name'].length">
<label for="channel_title">Name:</label>
<div class="input">
<input data-bind="channel.name" name="channel[name]" id="channel_title"/>
</div>
</div>
<div>
<ul>
edit: (params) ->
@set 'channel', Ems.Channel.find parseInt(params.id), (err) -> throw err if err
Ems.Category.load (err, categories) =>
throw err if err
@set 'categories', categories
console.log 'Categories returned: ', categories
# RETURNS:
#
# > Categories returned: [ Category, Category, Category ]
@luxerama
luxerama / post.html
Created March 30, 2012 09:04 — forked from kenmazaika/post.html
Embed Gist In Tumblr, File By File
<div class="gist">
<a href=
"https://gist.github.com/1870642.js?file=resque.rake">https://gist.github.com/1870642.js?file=resque.rake</a>
</div>
module Engine
def initialize
@engine_running = false
end
def start_engine
@engine_running = true
end
def stop_engine
@luxerama
luxerama / routing_helper.coffee
Created April 19, 2012 16:53
routeTo batman filter - This filter should cater for most routing applications
# Mixin to aid the compilation of routes
#
# PLEASE NOTE, this does not work with collections or nested routes/resources
#
# @mixin
# @author Vincent Siebert <vincent@siebert.im>
# @copyright (c) 2012 The Beans Group Ltd
Batman.mixin Batman.Filters,
# Filter to aid the compilation of non CRUD routes. Unfortunately because there is no way of resolving a keypath in an object when passing
@luxerama
luxerama / send_remote_syslog.php
Created May 13, 2012 21:06 — forked from troy/send_remote_syslog.php
Send UDP remote syslog message from PHP (RFC 3164)
<?php
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$msg = "<22>" . date('M j H:i:s ') . $program . ' ' . $component . ': ' . $message;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
# replace these with settings provided by Papertrail
socket_sendto($sock, $msg, strlen($msg), 0, 'logs.papertrailapp.com', 1111);
socket_close($sock);
}
@luxerama
luxerama / test.coffee
Created May 15, 2012 16:02
Overriding batman.js model save
class Xyz.TestModel extends Batman.Model
save: (options, callback) ->
super options, (err, record, env) =>
console?.log record
testModel = new Xyz.TestModel()
testmodel.save null, (err) ->
@luxerama
luxerama / capistrano_database_yml.rb
Created May 24, 2012 14:03 — forked from weppos/capistrano_database_yml.rb
Provides a couple of tasks for creating the database.yml configuration file dynamically when deploy:setup is run.
#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category:: Capistrano
# Package:: Database
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2010 The Authors
@luxerama
luxerama / rename_rails3.rb
Created June 20, 2012 08:58 — forked from vertis/rename_rails3.rb
Simple script that can be used to rename a rails3 app
#!/usr/bin/env ruby
require 'fileutils'
require 'tempfile'
def replace_in_file(filename,oldvalue,newvalue)
temp_file = Tempfile.new(File.basename(filename))
contents = File.read(filename)
changed_contents = contents.gsub(oldvalue,newvalue).gsub(oldvalue.downcase,newvalue.downcase)
temp_file.print(changed_contents)
@luxerama
luxerama / query.rb
Created November 14, 2012 12:29
Mongoid Moped query in order to get the distance returned by geospacial MongoDB queries
# This works as of Mongoid v3
Model.collection.database.command(geoNear: "models", near: [50, 50])