Skip to content

Instantly share code, notes, and snippets.

View rigelstpierre's full-sized avatar

Rigel St. Pierre rigelstpierre

View GitHub Profile
@rigelstpierre
rigelstpierre / Wordpress Short Titles
Created October 14, 2011 05:51
A quick way to shorten wordpress titles.
function ShortenText($text) {
// Change to the number of characters you want to display
$chars_limit = 100;
$chars_text = strlen($text);
$text = $text." ";
$text = substr($text,0,$chars_limit);
$text = substr($text,0,strrpos($text,' '));
// If the text has more characters that your limit,
//add ... so the user knows the text is actually longer
@rigelstpierre
rigelstpierre / flexslider.jquery.js
Created November 5, 2012 20:50
jQuery Show/Hide Elements
/*
* jQuery FlexSlider v2.1
* http://www.woothemes.com/flexslider/
*
* Copyright 2012 WooThemes
* Free to use under the GPLv2 license.
* http://www.gnu.org/licenses/gpl-2.0.html
*
* Contributing author: Tyler Smith (@mbmufffin)
*/
require 'digest/md5'
class RemoveDuplicateRecords < ActiveRecord::Migration
def self.up
addresses = {}
for Listing.find_each do |listing|
digest = Digest::MD5.hexdigest("#{listing.street_address}#{listing.apartment_no}")
if addresses.include?(digest)
listing.destroy
else
require 'digest/md5'
class RemoveDuplicateRecords < ActiveRecord::Migration
def self.up
addresses = {}
Listing.find_each do |listing|
digest = Digest::MD5.hexdigest("#{listing.street_address}#{listing.apartment_no}")
if addresses.include?(digest)
listing.destroy
else
class Photo < ActiveRecord::Base
belongs_to :listing, :counter_cache => true
scope :by_landlord, lambda {|landlord_id| joins(:listing).where('landlord_id = ?', landlord_id)}
default_scope order('"photos"."index" ASC')
attr_accessible :index, :image, :image_url, :image_processing
attr_accessor :is_pre_listing
validates_presence_of :listing_id, :unless => :is_pre_listing
case service_time.relation_to_sunday
when "Current"
previous_sunday
when "Before"
if date.wday == service_time.day_of_week
#use date and time
actual_service_time = service_time_with_offset(service_time, date, true)
return upcoming_sunday ? time >= actual_service_time : return previous_sunday
FF.calendarPosts = function() {
FF.el.calendar_post_list_item.click(function (e) {
e.preventDefault();
// set vars on this
var $this = $(this),
item_title = $this.data('title'),
item_permalink = $this.data('permalink'),
item_date = $this.data('date'),
@rigelstpierre
rigelstpierre / tacky.rb
Created June 13, 2014 16:40
Tic Tac Toe Code Challenge
require "color_text"
class Tacky
def initialize
# all places that are possible wins
@columns = [
[:a1,:a2,:a3],
[:b1,:b2,:b3],
[:c1,:c2,:c3],
@rigelstpierre
rigelstpierre / gist:809e8e74f76840521320
Last active August 29, 2015 14:09
Create new track friends api

Path: /api/app/users/#{facebook_uid}/friends or /api/app/users/#{email}/friends

Method: POST

Params: :uids, :emails, :user

Expected Response: {"data"=&gt;{"tracked_friends_count" =&gt; "10"}

@rigelstpierre
rigelstpierre / spotify.rb
Created December 7, 2014 19:18
Spotify Auth
def spotify
self.validate_spotify_auth_token if self.spotify_auth_token.present?
config = {
:access_token => self.spotify_auth_token, # initialize the client with an access token to perform authenticated calls
:raise_errors => true, # choose between returning false or raising a proper exception when API calls fails
# Connection properties
:retries => 0, # automatically retry a certain number of times before returning
:read_timeout => 10, # set longer read_timeout, default is 10 seconds
:write_timeout => 10, # set longer write_timeout, default is 10 seconds