Skip to content

Instantly share code, notes, and snippets.

View bradylove's full-sized avatar

Brady Love bradylove

  • Pivotal
  • Highlands Ranch, CO
View GitHub Profile
def update
@post = Post.find(params[:id])
@post.published_at = @post.update_published(params[:published], @post.published_at)
if @post.update_attributes(params[:post])
redirect_to @post, :notice => "Post has been updated."
else
flash[:alert] = "Post has not been updated."
render :action => "edit"
class Post < ActiveRecord::Base
def update_published(published, published_at)
if published == true and published_at.nil? == true
Time.now
elsif published == false
nil
elsif published == true and published_at.nil? == false
published_at
end
end
class Post < ActiveRecord::Base
before_save :published_at_value
private
# TODO: Needs Refactoring
def published_at_value
if self.published == true and self.published_at.nil? == true
self.published_at = Time.now
elsif self.published == false
class TagsController < ApplicationController
def index
@tags = Post.published_posts.tag_counts.where("name like ?", "%#{params[:q]}%").order(:name)
@json = []
@tags.each do |tag|
@json << {:tag => tag.name, :freq => tag.count}
end
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
function path()
{
var args = arguments,
result = []
;
for(var i = 0; i < args.length; i++)
result.push(args[i].replace('@', '/javascripts/'));
return result
@bradylove
bradylove / github.rb
Created May 31, 2011 12:37
Small model to get list of repos and create links
class Github
def initialize(username)
@username = username
end
def get_repos
base_url = "http://github.com/api/v2/json/repos/show/"
url = "#{base_url}#{@username}"
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
require "typhoeus"
require "json"
require "./Constants"
include Constants
include Typhoeus
class Github
def auth
request = Request.new("https://api.github.com",
:username => USERNAME,
require "typhoeus"
require "json"
require "./Constants"
include Constants
include Typhoeus
class Gist
def build_gist
gist = { :description => "This is a test",
@bradylove
bradylove / gist:1021785
Created June 12, 2011 17:24
Convert devise views to haml
find . -name '*erb' | xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")};rm #{i}"}' | bash