Skip to content

Instantly share code, notes, and snippets.

Bryan Buchanan bryanbuchanan

Block or report user

Report or block bryanbuchanan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View remove_empty_folders.py
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)
View rename_replace.py
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)
@bryanbuchanan
bryanbuchanan / GetShapeArea.jsx
Last active Sep 12, 2019
Script to find the area of shapes in Adobe Illustrator
View GetShapeArea.jsx
/* 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');
View client-size-image-resize.js
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;
View image-download-blocker.html
<!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">
@bryanbuchanan
bryanbuchanan / flickr_id_to_profile.php
Created Apr 23, 2013
Takes a Flickr users's ID and finds their profile on Flickr.com
View flickr_id_to_profile.php
<?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,
@bryanbuchanan
bryanbuchanan / lltoXY.js
Last active Dec 16, 2015
Function that takes latitude/longitude of a single point and returns x/y position as plotted on an equirectangular map.
View lltoXY.js
// 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 / retinacanvas.js
Last active Dec 16, 2015
Makes HTML5 canvas elements support @2x displays by doubling their size, then scaling them down to 50%. Requires jQuery.
View retinacanvas.js
// Function
function retinaCanvas($canvas, context) {
$canvas.each(function() {
$(this).prop({
width: $(this).width() * 2,
height: $(this).height() * 2
});
context.scale(2,2);
});
}
@bryanbuchanan
bryanbuchanan / logger.js
Last active Oct 13, 2015
Wrapper for console.log command
View logger.js
// 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 {
You can’t perform that action at this time.