Skip to content

Instantly share code, notes, and snippets.

View chrisle's full-sized avatar
💭
probably partying...

Chris Le (TRIODE) chrisle

💭
probably partying...
View GitHub Profile
@chrisle
chrisle / hashes.js
Last active September 16, 2020 13:12
Compute hashes for Google Docs
function computeMD5(str) {
var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, str);
return Utilities.base64Encode(digest);
}
function computeSHA1(str) {
var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, str);
return Utilities.base64Encode(digest);
}
/**
* To answer @AnnieCushing's question on Twitter:
* https://twitter.com/AnnieCushing/status/806518054368739329
*
* Author: Chris Le - @iamchrisle
*
* There's a few ways to do this.
* - Like @SimoAhava suggested, server redirects that strips parameters if you
* have the ability to control the server.
@chrisle
chrisle / gist:4206925
Created December 4, 2012 18:01
newspaper to seomoz
require 'mechanize'
require 'linkscape'
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
# Put your state here
state = "PA"
page = agent.get "http://newsmap.mhlakhani.com/data/US-#{state}"
@chrisle
chrisle / scraper.js
Last active July 2, 2016 01:57
Scrape Billboard Hot 100 and create an array of objects
/**
* Install x-ray with: 'npm install x-ray'
* (Also see: https://github.com/lapwinglabs/x-ray)
*
* Run with: node scraper.js
*
* Result:
*
* [ { rankCurrent: '1',
* rankLast: 'Last Week: 1',
@chrisle
chrisle / gist:8588282
Created January 23, 2014 22:40
TLDR - Google Analytics
/**
* The very simplest explanation of how GA works in JavaScript is that it's simply an array.
* The GA tag (not the new Universal tag) looks similar to this:
*/
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-y']);
_gaq.push(['_trackPageview']);
(function () {
@chrisle
chrisle / gist:7055839
Last active December 25, 2015 23:19
Should an API allow for polling or instead push results? What do you prefer?

Question

If http://localhost/api/do_job kicks off a job on the backend that will take 45-120 seconds to complete, what should the API return?

POLL) Return 202 Accepted + a URL polling end point.

Eg:

202 Accepted
{ "job_id": 103859195, "poll": "http://localhost/poll/103859195", "complete": "0%" }
@chrisle
chrisle / gist:6368604
Created August 28, 2013 17:14
Humanize an underscored or camel cased string in JavaScript
/**
* Humanize a string. Turns underscored or camel cased string into human readable strings
*
* @example
* TextUtils.humanize( 'keyword_category' ); // => "Keyword Category"
* TextUtils.humanize( 'keywordCategory' ); // => "Keyword Category"
*
* @return {String}
*/
humanize: function(str) {
class Puzzle
attr_accessor :field
def initialize
self.field = true
end
def run
puts field.inspect # => true
@chrisle
chrisle / gist:5129460
Created March 10, 2013 17:06
Split Array By
/**
* Adds empty elements to an array
*
* @example
* A1: hello
* A2: world
*
* =splitArrayBy(A1:A2, 3)
*/
function splitArrayBy(array, n) {
@chrisle
chrisle / nico.js
Created February 11, 2013 20:14
Nicos bookmarklet
// This is to be used as a bookmarklet
// Supposed to show a prompt where you pick if you want to do a site: search alpha using 'a' or bravo using 'b'
// However, this isn't working as a bookmarklet but does work in the live w3 editor
javascript:var name=prompt("Please enter your name \n a = alpha \n b = bravo","x");
switch (name) {
case "a":
location.href='http://www.google.com/search?q=site%3A'+document.domain.replace('www.','')+" alpha"
break;
case "b":