Skip to content

Instantly share code, notes, and snippets.

View timnovinger's full-sized avatar

Tim Novinger timnovinger

View GitHub Profile
@timnovinger
timnovinger / Tweet Caching.rb
Created April 22, 2010 17:00
Twitter Caching
class Tweet < ActiveRecord::Base
def self.fetch_new
# attempt to connect and authenticate to Twitter
httpauth = Twitter::HTTPAuth.new(ENV['TWITTER_USR'], ENV['TWITTER_PWD'])
client = Twitter::Base.new(httpauth)
# fetch a new tweet, cache it to the database, and then return it
Tweet.create :text => client.user_timeline.first.text
client.user_timeline.first.text
// ===========================================================================================================
// NAME
//
// DESCRIPTION GOES HERE
//
// Example
// Mootools style: var *name* = new *NAME*('.tooltip', {'options':'hash', 'syntax':'example'});
// jQuery style: $(element).*name*({'options':'hash', 'syntax':'example'});
//
// Options
#!bash
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
---
:update_sources: true
:bulk_threshold: 1000
:verbose: true
:backtrace: false
:benchmark: false
gem: --no-ri --no-rdoc
:sources:
- http://gems.rubyforge.org/
- http://gemcutter.org
# TRUNCATE BY WORD COUNT
def snippet (text, wordcount, separator="...")
text.split[0..(wordcount-1)].join(" ") + (text.split.size > wordcount ? separator : "")
end
## EXAMPLE USAGE
[PHP]
;;;;;;;;;;;
; WARNING ;
;;;;;;;;;;;
; This is the default settings file for new PHP installations.
; By default, PHP installs itself with a configuration suitable for
; development purposes, and *NOT* for production purposes.
; For several security-oriented considerations that should be taken
; before going online with your site, please consult php.ini-recommended
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
httpauth = Twitter::HTTPAuth.new( current_account.twitter_username, current_account.twitter_password )
client = Twitter::Base.new(httpauth)
# TO DO -- Yep, should filter the request to only get tweets since the last check
client.friends_timeline.each do |tweet|
# TO DO -- Yep, need to check to see if the tweet is already in there
status = Status.create(
:status_created_at => tweet.status_created_at,
:status_id => tweet.id,
:message => tweet.text,
:source => tweet.source,
@timnovinger
timnovinger / file.html
Created November 17, 2009 17:13 — forked from anonymous/file.html
Code Snippets from Mobile Webkit Development Talk on 11/16
<!-- ============================================================== -->
<!-- = Code Snippets from Mobile Webkit Development Talk on 11/16 = -->
<!-- ============================================================== -->
<!-- =========================== -->
<!-- = Conditional Stylesheets = -->
<!-- =========================== -->
<link media="only screen and (max-device-width: 480px)" href="small-device.css" type= "text/css" rel="stylesheet">
@timnovinger
timnovinger / bodyid.rb
Created October 14, 2009 13:37
Automatic Body ID in Rails
###############################################
# place in /app/helpers/application_helper.rb #
###############################################
def bodytag_id
a = controller.class.to_s.underscore.gsub(/_controller$/, '')
b = controller.action_name.underscore
"#{a}-#{b}".gsub(/_/, '-')
end