Skip to content

Instantly share code, notes, and snippets.

@mhgbrown
mhgbrown / main.js
Last active July 6, 2019 11:13
Vue, Server Side Rendering, and Handling Dependencies that Require a Browser Environment
Vue.component('apexchart', () => {
// NB: tell webpack to include the dynamic import within
// the main bundle instead of splitting into other bundles.
// https://webpack.js.org/api/module-methods/#import-
return import(
/* webpackMode: "eager" */
'vue-apexcharts'
)
})
@mhgbrown
mhgbrown / image_proxy_controller.rb
Last active November 8, 2022 15:09
Proxy images through a Rails controller
require 'base64'
require 'net/http'
class ImageProxyController < ActionController::Base
def get
url = URI.parse(Base64.decode64(params[:url]))
image = Net::HTTP.get_response(url)
send_data image.body, type: image.content_type, disposition: 'inline'
end
end
@mhgbrown
mhgbrown / get_public_google_profile_info_from_emails.py
Created April 17, 2017 14:27
Get public Google profile information from email addresses
# Some scratch code to get public profile information from Google
# based on a list of email addresses. Look at the People Search API
# for more details
import httplib2
import logging
from urllib.parse import urlparse, parse_qs
# via https://github.com/google/google-api-python-client
from apiclient.discovery import build
@mhgbrown
mhgbrown / newsletter.js
Created February 21, 2017 17:31
AJAX Submission of Mailchimp Form with Internationalization; Uses jQuery
var SUCCESS_MESSAGES = {
'en': {
'complete the subscription': 'Confirm the subscription in your inbox',
'default': 'Confirm the subscription in your inbox'
},
'de': {
'complete the subscription': 'Bestätigen Sie das Abonnement in Ihrer Inbox',
'default': 'Bestätigen Sie das Abonnement in Ihrer Inbox'
}
}
@mhgbrown
mhgbrown / RequestTimeTrackingMiddleware.py
Created November 18, 2016 16:28
Django Middleware to track request time to Mixpanel
import datetime
import uuid
from django.conf import settings
from mixpanel import Mixpanel
from mixpanel_async import AsyncBufferedConsumer
mp = Mixpanel(settings.MIXPANEL_API_TOKEN, consumer=AsyncBufferedConsumer())
@mhgbrown
mhgbrown / ng-error.directive.js
Last active August 18, 2016 10:04
ES6 Class-based Angular 1.x ngError Directive: could be more "ES6-y", but you get the gist 😉
class ngError {
constructor($parse) {
this.$parse = $parse;
this.restrict = 'A';
}
link(scope, $element, attrs) {
var onError = this.$parse(attrs['ngError']);
@mhgbrown
mhgbrown / dynamic-favicon.js
Created March 21, 2016 16:30
Create a favicon on page load based on the CSS color of the first few matching elements
/**
* Create a FAVICON_DIMENSIONxFAVICON_DIMENSION PNG favicon based on the
* CSS color of the first NUM_COLORED elements with the class COLORED_CLASS.
* The favicon is generated with the pattern:
* color 1 | white
* color 2 | white
* color 3 | white
* etc...
*
*/
@mhgbrown
mhgbrown / gist:f9a692b3a6135c11f775
Created July 9, 2015 18:30
retrieve all text nodes which are not made of space characters using TreeWalker API
/**
* Retrieve all text nodes which are not
* made of space characters.
* @return {Array} A collection of text nodes
**/
var getTextNodes = function() {
var walker = document.createTreeWalker(
this.rootElement,
NodeFilter.SHOW_TEXT,
null,
@mhgbrown
mhgbrown / deprecation_warning.txt
Created February 5, 2013 23:52
Prominent deprecation warning
mhyyyyhm
hyyyyyyyyh
NhyyyyyyyyyyhN
NyyyyyyyyyyyyyyN
myyyyyyyooyyyyyyym
dyyyyyyy+ +yyyyyyyd
dyyyyyyy/ /yyyyyyyd
hyyyyyyy: :yyyyyyyh
Nhyyyyyyy- -syyyyyyhN
Nyyyyyyys. .syyyyyyyN