Skip to content

Instantly share code, notes, and snippets.

View bryanbuchanan's full-sized avatar

Bryan Buchanan bryanbuchanan

View GitHub Profile
@bryanbuchanan
bryanbuchanan / logger.js
Last active October 13, 2015 23:38
Wrapper for console.log command
// Logger only works when develop == true
var develop = true;
function log(message, line) {
if (window.console && window.log && develop) {
var line = typeof line !== "undefined" ? line : false;
if (line) {
if (typeof message === "string") {
console.log(message + " (Line " + line + ")");
} else {
@bryanbuchanan
bryanbuchanan / retinacanvas.js
Last active December 16, 2015 10:59
Makes HTML5 canvas elements support @2x displays by doubling their size, then scaling them down to 50%. Requires jQuery.
// Function
function retinaCanvas($canvas, context) {
$canvas.each(function() {
$(this).prop({
width: $(this).width() * 2,
height: $(this).height() * 2
});
context.scale(2,2);
});
}
@bryanbuchanan
bryanbuchanan / lltoXY.js
Last active December 16, 2015 10:59
Function that takes latitude/longitude of a single point and returns x/y position as plotted on an equirectangular map.
// Function
function lltoXY(options) {
var x = (options.lon + 180) * (options.width / 360);
var y = ((options.lat * -1) + 90) * (options.height / 180);
return { x: x, y: y };
}
// Usage
var position = lltoXY({
lat: 25.26,
@bryanbuchanan
bryanbuchanan / flickr_id_to_profile.php
Created April 23, 2013 01:52
Takes a Flickr users's ID and finds their profile on Flickr.com
<?php
if (isset($_POST)) {
// Get user ID
$user_id = $_POST['user_id'];
// Data to send to Flickr API
$data = array(
"method" => "flickr.people.getInfo",
"user_id" => $user_id,
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<!-- Test image -->
<img src="http://m1.22slides.com/bryanbuchanan/4317_image_374612.jpg" alt="Image">
imgLoader = new Image();
imgLoader.onload = function(data) {
// Desired size
var max_width = 600;
var max_height = 600;
// Get image dimensions
var original_width = imgLoader.width;
var original_height = imgLoader.height;
@bryanbuchanan
bryanbuchanan / GetShapeArea.jsx
Last active October 28, 2024 16:16
Script to find the area of shapes in Adobe Illustrator
/* Save this file with a jsx extension and place in your
Illustrator/Presets/en_US/Scripts folder. You can then
access it from the File > Scripts menu */
var decimalPlaces = 3;
if (app.documents.length > 0) {
if (app.activeDocument.selection.length < 1) {
alert('Select a path');
@bryanbuchanan
bryanbuchanan / cdtms.markdown
Created July 18, 2014 20:55
A Pen by Bryan Buchanan.
import os
import sys
directory = os.path.dirname(os.path.realpath(sys.argv[0]))
for subdir, dirs, files in os.walk(directory):
for filename in files:
if filename.find('old_suffix_1') > 0:
subdirectoryPath = os.path.relpath(subdir, directory)
filePath = os.path.join(subdirectoryPath, filename)
import os
import sys
directory = os.path.dirname(os.path.realpath(sys.argv[0]))
for dirpath, dirnames, files in os.walk(directory):
if not files:
os.rmdir(dirpath)