Skip to content

Instantly share code, notes, and snippets.

@drakemccabe
drakemccabe / .htaccess
Created May 3, 2016 17:11
Rewrite urls to WWW without changing request's original protocol
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^<HOST>.com$ [NC]
RewriteRule ^(.*)$ http://www.<HOST>.com/$1 [L,R=301]
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^<HOST>.com$ [NC]
RewriteRule ^(.*)$ https://www.<HOST>.com/$1 [L,R=301]
@drakemccabe
drakemccabe / resize.bash
Created May 3, 2016 17:09
Find all files under a certain size or dimension and then resize
# Find files over 300kb and resize to 300kb
identify -format '%b %h %i\n' ./*.png |
awk '$1 > 300000 {sub(/^[^ ]* [^ ]* /, ""); print}' |
tr '\n' '\0' |
xargs -0 mogrify -define png:extent=300KB
# Find files over 600px width and resize to 600px while keeping ratio
identify -format '%w %h %i\n' ./*.png |
@drakemccabe
drakemccabe / webpage_to_mongodb.rb
Last active August 23, 2016 02:57
Web Page to MongoDB for seeding test data
require 'nokogiri'
require 'open-uri'
require 'mongo'
x = true
while x
content = ""
puts "enter site"
site = gets.chomp
@drakemccabe
drakemccabe / test-jsonp-request.html
Created March 31, 2016 12:53
HTML page with script to test JSONP request.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
var requestUrl = "";
window.onload = function() {
$.getJSON(requestUrl, {}, function (data) {
document.write(JSON.stringify(data));
console.log(data);
}).error(
function(jqXHR, statusText, errorThrown) {
alert(jqXHR.status);
@drakemccabe
drakemccabe / index.html
Created January 20, 2016 03:13
basic responsive design template for marketo email
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--[if !mso]><!-->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<link rel="stylesheet" type="text/css" href="styles.css">
@drakemccabe
drakemccabe / convert.rb
Last active January 15, 2016 21:45
Format JSON file
require "json"
require "pry"
file_raw = File.read("./keywords.json")
file = JSON.parse(file_raw)
counter = 1
file["results"]["Keywords"].each_with_index do |keyword, index|
file["results"]["Keywords"][index] = { keyword["url"].split('/'[-1]).last => keyword }
end
def twitter_data
[{"LaunchAcademy_"=>
{"description"=>
"A 10 week, intensive bootcamp teaching you how to code with a focus on Ruby on Rails",
"last twenty tweets"=>
["RT @chrisccerami: While learning web development I created a map of all of the shows @Screamales have played and damn @DonGiovanniRecs http…",
"6 ways to quantify your code and why you need to do it: http://t.co/1WKtpo41tP by @kevinrcasey http://t.co/lulzPLTY8c",
"Do more of what you want at work. How to create productive partnerships: http://t.co/QpYpHhHEid by @benvoss",
"RT @Pistachio: SO rad. bunch of local women learning to code with @gdiBoston at @HubSpot right now: http://t.co/jaIxK7suOj",
"RT @STWatkins78: Huge breakthrough on my breakable toy today...can upload local file to soundcloud from my app...time for a beer! #LaunchAc…",
<?xml version="1.0"?>
<root>
<!-- Google Chrome -->
<vkopenurldef>
<name>KeyCode::VK_OPEN_URL_APP_Chrome</name>
<url type="file">/Applications/Google Chrome.app</url>
</vkopenurldef>
<!-- Atom -->