Skip to content

Instantly share code, notes, and snippets.

@phillyslick
phillyslick / mobile.rb
Last active December 18, 2015 21:09
Rails view helpers for serving either mobile or full-sized image, as well as detecting if client is mobile...
def mobile?
true if /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.match(request.user_agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|k
@phillyslick
phillyslick / cart.css.scss
Last active December 18, 2015 21:58
Basic outline of shopping cart that pops in from the right.
// --------------- CART
aside#cart{
position:fixed;
top:0%;
right:-100%;
z-index:9999;
width:100%;
height:300px;
#closeCart{
cursor:pointer;
@phillyslick
phillyslick / fullpath_snippet.rb
Created June 26, 2013 18:59
Rails Fullpath in View
"#{request.protocol}#{request.host_with_port}#{request.fullpath}"
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<link rel="stylesheet" type="text/css" media="screen" href="css/master.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
@phillyslick
phillyslick / gist:7243950
Created October 31, 2013 03:21
js - test if an object has a property defined
function has(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
<div class="row">
<div class="large-12 columns calendar-container">
<h3 class="month">
<a href="/admin/analytics?class=cal-larr&amp;date=2013-11-01">&lt;</a>
December 2013
<a href="/admin/analytics?class=cal-rarr&amp;date=2014-01-01">&gt;</a>
</h3>
<section class="calendar" role="main">
<ul class="day-row">
<li class="day">SUN</li>
module CalendarHelper
def calendar(date = Date.today, &block)
Calendar.new(self, date, block).table
end
class Calendar < Struct.new(:view, :date, :callback)
HEADER = %w[SUN MON TUE WED THU FRI SAT]
START_DAY = :sunday
delegate :content_tag, to: :view

Deploy Rails app to digitalocean with nginx, unicorn, capistrano & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh [email protected]

Add ssh fingerprint and enter password provided in email

## Importing Data from CSV to Rails psql
## Code is essentially ripped from:
## here: http://stackoverflow.com/questions/14534522/ruby-csv-parsing-string-with-escaped-quotes (thanks!)
## and here: http://technicalpickles.com/posts/parsing-csv-with-ruby/ (double thanks!)
## using Sequel Pro for OSX to tear up / navigat the murkey waters of a Wordpress Database
csv_data = File.read('data.csv').gsub(/\\"/,'""')
csv = CSV.new(csv_data, {headers: true})
arrayed_csv = csv.to_a
Yo Yo. Emcee Noesis.