Skip to content

Instantly share code, notes, and snippets.

@rdetert
rdetert / _form.html.erb
Last active December 18, 2015 19:39
Uses Pikaday and Moment JS jQuery plugins to make a user-friendly DateTime picker to work with Rails
<%= stylesheet_link_tag "pikaday", :media => "all" %>
<%= form_for(@news) do |f| %>
<!-- Generate HTML -->
<%= form_datetime_selector_helper(:obj => f,
:field_name => :publish_date,
:label_name => 'Publish Date',
:date => @news.publish_date).html_safe %>
<% end %>
@rdetert
rdetert / dragonfly.rb
Created May 8, 2013 04:07
How to get Dragonfly working on with a Mongo Datastore using Mongoid 3 on both localhost and Heroku. It's a little bit of a pain and here is the quick and dirty approach without Monkey Patching.
require 'dragonfly'
app = Dragonfly[:images]
mconfig = Mongoid.load!("config/mongoid.yml", Rails.env)
app.datastore = Dragonfly::DataStorage::MongoDataStore.new
app.datastore.configure do |c|
cfg = mconfig['sessions']['default']
@rdetert
rdetert / vbox_savestate.sh
Created August 3, 2011 06:47
Save the State of all your VirtualBox Virtual Machines. Great if you need to reboot remotely.
#!/bin/sh
VBoxManage list runningvms | awk '{split($0, a, " {"); gsub(/\"/,"", a[1]); print a[1]}' | xargs -I {} -t VBoxManage controlvm {} savestate
@rdetert
rdetert / facebook_verify.rb
Created July 20, 2011 09:26
Rake Task to set whether a user has been Facebook verified or not using Omniauth
namespace :facebook do
desc "Check if users have updated their Facebook verification status"
task :update_user_verifiation_status => :environment do
require 'omniauth'
# get all users who are not currently verified
@users = User.joins(:authentications, :profile).where(:"authentications.provider" => "facebook", :"user_profiles.facebook_verified" => 0).select("users.id AS id, authentications.uid, authentications.access_token, user_profiles.facebook_verified")
@users.each do |user|
FB = OmniAuth::Strategies::Facebook.new("nothing")
@rdetert
rdetert / mp3_convert.sh
Created July 15, 2011 09:04
Want to convert your music files to mp3 because you've had the same CD in your car for 3 years? I thought so.
#!/bin/sh
vlc="/Applications/VLC.app/Contents/MacOS/VLC"
ext="mp3"
dest="/Users/ryan/Desktop/mp3/"
for ARG in "$@"; do
NEWFILE="$dest$(basename "$ARG").$ext"
$vlc -I dummy -vvv "$ARG" --sout "#transcode{acodec=mp3,ab=128,channels=2,samplerate=44100}:std{mux=raw,dst=\"$NEWFILE\",access=file}" vlc://quit
done
@rdetert
rdetert / omniauth_facebook_login.rb
Created July 2, 2011 22:46
Using Omniauth to Login to Facebook with an Access Token
FB = OmniAuth::Strategies::Facebook.new("nothing")
client = ::OAuth2::Client.new("nothing", "nothing", FB.client_options)
cached_token = "app_id_part|session_id_part|token_part" # or maybe you sent it from the iPhone
access_token = ::OAuth2::AccessToken.new(client, cached_token)
FB.instance_variable_set("@access_token", access_token)
FB.user_info
@rdetert
rdetert / abstract_email_controller.rb
Created June 28, 2011 23:54
Generate Email Body from Controller or Observer to Send via Delayed Job
# controllers/shared/abstract_email_controller.rb
module Shared
class AbstractEmailController < AbstractController::Base
include AbstractController::Rendering
include AbstractController::Layouts
include AbstractController::Helpers
include AbstractController::Translation
include AbstractController::AssetPaths
@rdetert
rdetert / README.txt
Created June 1, 2011 23:29
Setup Monitoring for a rake ts:dd job (Thinking Sphinx Delayed Delta)
The purpose of all this is to see if sphinx, thinking sphinx and thinking sphinx delayed delta are all working properly.
I created a test controller on a separate monit subdomain that simply generates and posts a test value and then uses curl to retrieve it. If the two values match, then sphinx is working properly with delayed delta.
This example assumes a Linux installation.
The file 'delayed_delta.sh' spawns the `rake ts:dd` process in the background, saving its PID to tmp/pids in your Rails project. You can start and stop it by running '/etc/init.d/delayed_delta.sh start' and '/etc/init.d/delayed_delta.sh stop'. You will use these in your monitoring to, see the monitrc snippet.
In a crontab, every X seconds or minutes, run 'ar_sphinx_mon.sh' to see if records are properly being inserted and indexed. If they aren't, then kill all Thinking Sphinx processes and monit should restart them.
@rdetert
rdetert / application.html.erb
Created March 1, 2011 06:28
How to logout completely from Facebook using Ruby on Rails and Devise + Omniauth. I'm just modifying the Omniauth Railscast http://railscasts.com/episodes/236-omniauth-part-2
<div id="user_nav">
<% if user_signed_in? %>
<img src="<%= user_avatar %>" id="main_avatar"> Signed in as <%= current_user.email %>.<br />
Not you?
<% if session[:fb_token].nil? %>
<%= link_to "Sign out", destroy_user_session_path %>
<% else %>
<%= link_to "Sign out", facebook_logout_path %>
<% end %>
/*
* Wrote this for the Design Board at equilter.com almost 10 years ago.
* Can't believe it still works and it's still in use!
* Should work for any DHTML browser known to man.
*
* Not so fond memories of getting it to work on MSIE 4 for Mac.
*
* To experience:
* 1. Add items to shopping cart
* 2. Click the Design Board at the top right.