Skip to content

Instantly share code, notes, and snippets.

View matt-west's full-sized avatar

Matt West matt-west

View GitHub Profile
@matt-west
matt-west / selected text position
Created June 22, 2011 18:13
Get the position of selected text
/*
* Script Name:
* Get Selected Text Position
*
* Description:
* Get the position of a selectedRange object.
*
* License:
* MIT
*/
@matt-west
matt-west / ruby-jpegtran.rb
Created April 18, 2012 15:54
Ruby Script for Optimizing JPEGs with jpegtran
#!/usr/bin/env ruby
files = Array.new
Dir.new(Dir.pwd).entries.each { |n| files.push(n) if File.file?(n) }
files.each do |file|
if file =~ /jpg|JPG:/i
system "jpegtran -copy none -optimize -outfile #{file} #{file}"
print "optimized #{file}\n"
end
@matt-west
matt-west / gist:3175207
Created July 25, 2012 09:06
Simple PHP Mailer Script
<?php
// This check relies on there being an <input> with the name 'submit' in your form.
// i.e. <input type="submit" name="submit">Send Form</input>
if (isset($_POST['submit'])) {
$to = "user@yourwebsite.com"; // Update with email.
$subject = "Application Submission";
// Create new fields here for each field in your form.
@matt-west
matt-west / haversine.js
Created August 10, 2012 08:30
Haversine Formula
// Haversine formula calculates the distance between two points (as the crow flies),
// taking into account the curvature of the earth.
// Returns a distance value in Kilometers.
function haversine(lat1, lon1, lat2, lon2) {
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();
@matt-west
matt-west / explaining-markdown.md
Created April 8, 2013 15:00
Post on Markdown for the Treehouse Blog.

Explaining Markdown

Markdown is a simple text-based markup language and conversion tool that allows writers to create great content for the web without having to worry too much about HTML. The syntax of the language is designed to be easy to learn and intuitive. It's ideal for people that write content for the web but that might be distracted by the HTML syntax.


Note: Markdown wasn't really designed as a language for creating complete web pages. It's more suitable for just content areas like the body of a blog post, an article or web page copy.

Markdown files use the .md or .text extensions.

@matt-west
matt-west / clearfix
Created September 9, 2013 14:52
CSS Clearfix
.clearfix {
*zoom: 1;
}
.clearfix:before,
.clearfix:after {
display: table;
line-height: 0;
content: "";
}
@matt-west
matt-west / box-sizing
Created September 9, 2013 15:11
box-sizing: border-box;
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
@matt-west
matt-west / mit-license.txt
Created September 9, 2013 15:57
MIT License
Copyright (c) 2013 Matt West <matt.west@kojilabs.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@matt-west
matt-west / apache-license.txt
Created September 9, 2013 15:58
Apache License
Copyright 2013 Matt West <matt.west@kojilabs.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@matt-west
matt-west / euclidean-distance.js
Created September 9, 2013 20:23
Euclidean Distance
/**
* @fileoverview Euclidean distance algorithm.
* @author matt.west@kojilabs.com (Matt West)
* @license Copyright 2013 Matt West.
* Licensed under MIT (http://opensource.org/licenses/MIT).
*/
/**
* Calculate the euclidean distance between two items in a dataset.