Skip to content

Instantly share code, notes, and snippets.

View jivebot's full-sized avatar

jivebot

  • Brightform Technology
  • Oregon, US
  • 20:34 (UTC -07:00)
View GitHub Profile
require 'rexml/parsers/pullparser'
require 'htmlentities'
class String
# Truncate strings containing HTML code
# Usage example: "string".truncate_html(50, :word_cut => false, :tail => '[+]')
def truncate_html(len = 30, opts = {})
opts = {:word_cut => true, :tail => ' ...'}.merge(opts)
p = REXML::Parsers::PullParser.new(self)
tags = []
@jonah-williams
jonah-williams / default.rb
Created March 16, 2010 23:36 — forked from ezmobius/default.rb
chef recipe to add delayed_job workers to monit to run them on Engine Yard cloud instances
#
# Cookbook Name:: delayed_job
# Recipe:: default
#
node[:applications].each do |app_name, data|
user = node[:users].first
case node[:instance_role]
when "solo", "app", "app_master"
@searls
searls / campfire-jenkins.rb
Created April 13, 2011 11:45
Tells campfire that a Jenkins build failed. Configure the post-build-task plugin ( https://wiki.jenkins-ci.org/display/JENKINS/Post+build+task ) to listen to the console output for failures and point it at a script like this one.
#!/usr/bin/ruby
require 'rubygems'
require 'tinder' #https://github.com/collectiveidea/tinder
campfire = Tinder::Campfire.new('your-subdomain',
:token => 'your token',
:ssl => true,
:proxy => 'http://your-proxy:1234')
room = campfire.rooms.first
@kylefinley
kylefinley / main.coffee
Created November 21, 2011 11:47
SproutCore 20 Routing + Statechart
require 'sproutcore'
require 'sproutcore-statechart'
require 'sproutcore-routing'
App = SC.Application.create()
App.GlobalNavController = SC.Object.create(
home: -> App.statechart.gotoState 'home'
about: -> App.statechart.gotoState 'about'
)
@dudleyf
dudleyf / gist:1477124
Created December 14, 2011 15:52
Handlebars Rake::Pipeline filter
require "json"
class HandlebarsFilter < Rake::Pipeline::Filter
def initialize(&block)
block ||= proc { |input| input.sub(/\.handlebars$/, '.js') }
super(&block)
end
def generate_output(inputs, output)
inputs.each do |input|
output.write "return Ember.Handlebars.compile(#{input.read.to_json})"
@scottburton11
scottburton11 / gist:1479734
Created December 15, 2011 03:43
Ember.js tree
<html>
<head>
<script src="javascripts/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="javascripts/ember.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
App = Ember.Application.extend();
App.Node = Ember.Object.extend({
name: null,
@ppcano
ppcano / animation_style.js
Created December 27, 2011 19:32
Creating modal views with emberjs and movejs
Luh.Ui.AnimationStyle = {
FROM_DOWN: 0
, FROM_UP: 1
, FROM_LEFT: 2
, FROM_RIGHT: 3
, NONE: 4
};
// It uses the awesome code from https://github.com/digitalBush/jquery.maskedinput/blob/master/src/jquery.maskedinput.js
App.MaskedInput = Ember.TextField.extend({
isIphone: function () { return (window.orientation != undefined) },
// browsers like firefox2 and before and opera doenst have the onPaste event, but the paste feature can be done with the onInput event.
pasteEvent: function (){
return (jQuery.browser.opera || (jQuery.browser.mozilla && parseFloat(jQuery.browser.version.substr(0,3)) < 1.9 ))? 'input': 'paste';
}.property().cacheable(),
// these keys will be ignored by the mask.
@gonzedge
gonzedge / application_controller.rb
Created January 5, 2012 02:34
Rails 3.1 - Adding custom 404 and 500 error pages
class ApplicationController < ActionController::Base
# ...
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: lambda { |exception| render_error 500, exception }
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception }
end
private
def render_error(status, exception)
@dudleyf
dudleyf / Assetfile
Created January 9, 2012 18:02 — forked from bstaats/Assetfile
Rake::Pipeline with multiple package inputs for an Ember project
require 'rake-pipeline-web-filters'
# package js
input 'packages/emberjs/dist', 'ember.js'
input 'packages/package_A'
input 'packages/package_B'
# project js
input 'lib'