Skip to content

Instantly share code, notes, and snippets.

View Twipped's full-sized avatar
💭
Furiously innovating

Jocelyn Badgley Twipped

💭
Furiously innovating
View GitHub Profile
@Twipped
Twipped / UploadedFile.php
Created September 1, 2012 23:11
Abstraction and sanitization of PHP's $_FILES superglobal.
<?php
class UploadedFile {
const ERR_OK = 0;
const ERR_TOO_LARGE = 1;
const ERR_INCOMPLETE = 2;
public $formname;
public $index = 0;
public function gravatar($email, $size = 70, $default = "monsterid") {
return "http://www.gravatar.com/avatar/" .
md5(strtolower($email)) .
"?s=" . (integer) $size .
"&d=" . urlencode($default) .
"&r=G";
}
SELECT
*,
( 3959 * acos( cos( radians(b.lat) ) * cos( radians( a.lat ) ) * cos( radians( a.lng ) - radians(b.lng) ) + sin( radians(b.lat) ) * sin( radians( a.lat ) ) ) ) AS distance
FROM `geozip` a
JOIN `geozip` b
WHERE b.zip = :zipcode
ORDER BY `distance`;"
@Twipped
Twipped / manview
Created February 20, 2013 18:54
Opens the passed manpage as a pdf in Preview. Invoked as `manview <command>`
#!/bin/sh
man -t $1 > /tmp/$1.ps
open -a "/Applications/Preview.app" /tmp/$1.ps
@Twipped
Twipped / gist:5841412
Created June 22, 2013 16:09
A Brief History of Sony Formats
  • 3.5" Floppy Disk: Won, due to no other competition.
  • Betamax: Lost to VHS
  • Component Recordable Video Disc: Recordable LaserDisk never took off.
  • DAT: Lost to CDs (Had some success in data backup)
  • Minidisc: Outlasted Phillips' Digital Compact Cassette, but ultimately lost to CD-R and flash storage
  • MultiMedia Compact Disc: Merged with Toshiba's Super Density Disc to become DVD
  • MemoryStick: Lost to MMC/SD/SDHD
  • SDDS: Failed to compete with DTS or Dolby Digital
  • SACD: Lost to audio DVDs and just DVDs in general
  • UMD: Failed to gain traction against the iPod.
So this is merge day.
And what have you done?
Another sprint over
And a new one nearly begun
And so this is merge day.
I hope you have fun
The ci builds are all crashing
The merge conflicts overrun
@Twipped
Twipped / gist:6903159
Last active August 13, 2017 16:23
SOA with Node.js Middle Layer

@ChiperSoft could you explain some of it in an email to me?

I suspect you may already have a general idea about it, since you've been arguing in favor of micro-services for some time. The basic idea is that you break your site down into lots of small applications.

Say you have a portal that is composed of multiple sections: front page, news, video, sports, discussion board, weather, video, etc. Each of those different sections would have their own backend content services driving them, independent APIs integrating with their own databases. You'd also have some form of centralized login & identity management service, some form of access control, and maybe a service for managing white-labeling if your portal is licensed by other companies.

Each of these sections on the site is a nodejs application by itself, responsible for handling only its own requests. This may be built using node's built in http server routines and a lot of in-house code, but most people are using some derivative of [Sencha Connect

@Twipped
Twipped / gist:7920139
Last active December 31, 2015 02:19
Introduction to Data Driven Documents (D3.js)
Basic Selection:
http://jsfiddle.net/7r9dS/1/ D3 iterates through LI elements, applying a css style and filling some text. select() takes any css selector
With Data:
http://jsfiddle.net/9fdLH/1/ D3 iterates through LI elements, filling in text from associated array.
Note that data() always applies to the selectAll() before it.
Entering:
http://jsfiddle.net/vu6hZ/1/ Enters data set, performing append() for every missing element, and then setting the initial value for that element
New appends will attach to the select() that happened _before_ the selectAll() that the data is attached to. If no initital selection, defaults to body tag.
@Twipped
Twipped / demo.js
Last active December 31, 2015 02:29
var redraw;
var formatNumber = d3.format(",d"),
formatDate = d3.time.format("%B %d, %Y"),
parseDate = d3.time.format('%d/%m/%Y').parse;
var views = {
states: PieChart('#states'),
religions: PieChart('#religions'),
parties: PieChart('#parties'),

You know, I never knew who Card was personally before I began this book. The back-and-forth between Miro and His Brother (as the Father) under the trees made me do an audible "What the fuck?" Then again later when Valentine professed her "faith" (probably the character least likely to do so). Those conversations were such a departure from the characters he originally created I thought there had to be an external influence on the author.

I don't think it has anything to do with the idea that the questions are more abstract, either. Instead, I feel like with every question, Card is just defaulting to the answer of "It's probably the will of god.'

Radical view shifts as a person passes into advanced adulthood are not at all uncommon. People's perspectives change, especially after they have children and start to feel old.

Are you certain it's Card making this statement and not just the character? I've read the book 4 or 5 times now and I've never felt that being presented as coming from Card. "The will