Skip to content

Instantly share code, notes, and snippets.

View ChuckJHardy's full-sized avatar

Chuck J Hardy ChuckJHardy

View GitHub Profile
@ChuckJHardy
ChuckJHardy / app.rake
Created May 29, 2011 12:34
Rake Task for Database Population
------------ From Rake Task
namespace :app do
# Checks and ensures task is not run in production.
task :ensure_development_environment => :environment do
if Rails.env.production?
raise "\nI'm sorry, I can't do that.\n(You're asking me to drop your production database.)"
end
end
@ChuckJHardy
ChuckJHardy / syntax_highlighting.py
Created September 24, 2011 01:01 — forked from mstarkman/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@ChuckJHardy
ChuckJHardy / buffered_logger.rb
Created February 7, 2012 14:49
New and Improved Logger for Rails
# config/initializers/buffered_logger.rb
module ActiveSupport
# Format the buffered logger with timestamp/severity info.
class BufferedLogger
NUMBER_TO_NAME_MAP = {0=>'DEBUG', 1=>'INFO', 2=>'WARN', 3=>'ERROR', 4=>'FATAL', 5=>'UNKNOWN'}
NUMBER_TO_COLOR_MAP = {0=>'0;37', 1=>'32', 2=>'33', 3=>'31', 4=>'31', 5=>'37'}
# http://api.rubyonrails.org/classes/Time.html#method-i-2D
DATE_FORMATTER = {0 => :db, 1 => :short, 2 => :long, 3 => :time}
@ChuckJHardy
ChuckJHardy / _partial1.html.erb
Created June 11, 2012 15:02 — forked from loginx/_partial1.html.erb
Dynamic partials in Batman.js
<div data-replace="item">
PARTIAL 1: <span data-bind="item.name"></span>
</div>
@ChuckJHardy
ChuckJHardy / dummy_controller.coffee
Created May 10, 2013 11:45
Batman.js Flash Messages V1
# controllers/dummy_controller.coffee
MyApp.flashSuccess "Record updated successfully!"
@ChuckJHardy
ChuckJHardy / dummy_controller.coffee
Created May 10, 2013 11:46
Batman.js Flash Messages V2
# controllers/dummy_controller.coffee
Classifieds.set "flash.success", "Record #{@get('record.title')} updated successfully!"
@ChuckJHardy
ChuckJHardy / javascript_template.js
Created May 10, 2013 11:52
Javascript Prototype Template
var HotelDescription = (function ($) {
"use strict";
var HotelDescription = function ($element) {
this.$long = $('.long-description', $element);
this.$short = $('.short-description', $element);
this.$more = $('.read-more', $element);
this.$less = $('.read-less', $element);
this.bind();
@ChuckJHardy
ChuckJHardy / Readme.md
Last active October 22, 2021 23:03
ZeroMQ + Node.js + Socket.io + UI for sending message from Ruby to a Javascript UI running on Node.js

Install the following requirements:

brew info zeromq
npm install zmq
npm install socket.io
gem install ffi-rzmq

Within the app directory run the following commands in different panes.

ruby worker.rb

@ChuckJHardy
ChuckJHardy / Gruntfile.js
Last active December 24, 2015 04:19
Gruntfile Express overrides for generator-angular 0.4.0
// Generated on 2013-09-27 using generator-angular 0.4.0
'use strict';
var path = require('path');
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
@ChuckJHardy
ChuckJHardy / run.js
Created September 28, 2013 16:19
Express Server for ZeroMQ, Socket.io and Angular.js
'use strict';
var express = require('express'),
app = express(),
http = require('http'),
server = http.createServer(app),
path = require('path'),
io = require('socket.io').listen(server),
fs = require('fs'),
zmq = require('zmq'),