Skip to content

Instantly share code, notes, and snippets.

View devongovett's full-sized avatar

Devon Govett devongovett

View GitHub Profile
@devongovett
devongovett / gist:2218587
Created March 27, 2012 18:11
get a blob from a canvas
function getBlob(canvas) {
var data = atob(canvas.toDataURL().replace('data:image/png;base64,', '')),
bytes = new Uint8Array(data.length);
for (var i = 0, len = data.length; i < len; i++) {
bytes[i] = data.charCodeAt(i) & 0xff;
}
var bb = new BlobBuilder();
bb.append(bytes.buffer);
const pageQuery = createQuery(); // create a top-level query
const App = () => (
// rendering MovieList automatically composes `MovieList.fragment` into the query.
<Connect
query={query(pageQuery)}
children={({ loaded, data }) => {
let result = pageQuery(data);
return <MovieList data={result.movieList} />;
}} />
);
@devongovett
devongovett / translate.js
Created February 2, 2014 23:14
Use PhantomJS to translate stdin to english using Google Translate. Useful as a textmate command or just a command line tool.
#!/usr/bin/env phantomjs
var system = require('system');
var text = encodeURIComponent(system.stdin.read());
var url = "http://translate.google.com/#auto/en/" + text;
var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0';
page.onConsoleMessage = function (msg) {
@devongovett
devongovett / index.js
Created August 13, 2016 18:08
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var AV = require('av');
//require('mp3');
player = AV.Player.fromURL('http://static.marco.org/Jskjlf0YhqA.mp3').play();
@devongovett
devongovett / spinner.jade
Created July 15, 2013 01:12
Simple image-free loading spinner using Jade and Stylus
.spinner
- for (var i = 1; i <= 12; i++)
span
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
char * number2filename(char *start, int digits, int num, char *end) {
int size = strlen(start) + strlen(end) + 1;
int formatSize = size + 3 + log10(digits) + 1;
char *format = (char *)malloc(formatSize);

Renaming import

I'm looking for name suggestions for my import module. The purpose of the tool is to add file importing abilities to JavaScript and CoffeeScript files via a #import directive similar to other languages.

import is a bad name for the module for a number of reasons:

  1. import is a reserved word in JavaScript/CoffeeScript so you cannot write var import = require('import') without getting syntax errors.
  2. The import command line tool conflicts with another tool of the same name which is commonly installed on Linux and Mac systems as part of the Imagemagick package.

For these reasons, I'm looking for a new name. The criteria are basically that the name must be available on npm and it must not be a JS reserved word. Here are a few that I thought of:

AV.loadModule = function() {
var Module = require('module');
var contextLoad = Module._contextLoad;
Module._contextLoad = true;
var AV = global.AV;
global.AV = require('av');
var ret = require.apply(null, arguments);
/*
* RSS Subscription Count Node.js Proxy Server
* Devon Govett
* Public Domain
*
* This script is a simple proxy server for my blog's RSS feed that keeps track of requests
* to the feed and attempts to guess a subscriber count.
* Google Reader represents the majority of my subscriber base, and they give you actual
* subscriber numbers when their spider requests your feed. Other aggregators do something similar.
* Otherwise, this script tracks unique IP addresses over a 24 hour period.
<!doctype html>
<script>
function pause() {
console.log('pause')
node.disconnect()
}
function play() {
console.log('play');