Skip to content

Instantly share code, notes, and snippets.

View stefl's full-sized avatar

Stef Lewandowski stefl

View GitHub Profile
@stefl
stefl / fix.js
Created May 19, 2018 15:35
Fix for Next.js / React SSR meta tags have URL-encoded content
// React SSR renders out <meta tags with URL-encoded values.
// That's bad if you need query parameters in your URLs.
// Before: <meta property="og:image"
// content="https://makelight-prismic-images.imgix.net/7f97d951970bbb15a8b3744e4c69499ffe969d66_img_1010.jpg?w=1200&amp;h=630&amp;fit=crop&amp;crop=entropy&amp;auto=format&amp;ixlib=js-1.1.1" class="next-head"/>
// (Notice the &amp;s in the URL)
//
// After: <meta property="og:image"
// content="https://makelight-prismic-images.imgix.net/cfb3a074bfcab5793eded64ef077dd6260d6d89b_img_0578.jpg?w=1200&h=630&fit=crop&crop=entropy&auto=format&ixlib=js-1.1.1" class="next-head"/>
// (Notice &amp; is now correctly &
//
# encoding: utf-8
module Prismic
class Memcache
def initialize(max_size=100)
end
def set(key, value, expired_in = nil)
@stefl
stefl / designer.html
Created April 3, 2015 12:01
designer
<link rel="import" href="../core-drawer-panel/core-drawer-panel.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-item/core-item.html">
<polymer-element name="my-element">
<template>
<style>
@stefl
stefl / Why hack.md
Last active December 18, 2015 12:28
Why Hack?

Why Hack?

At Makeshift we’re rapidly hacking on digital products that give a leg up to the little guy. We're a team of hackers, designers and product people who get out of bed each morning excited (okay, most mornings) to make new apps that bring our ideas to life.

We're kicking off our new blog series, "Why Hack?" featuring you. We want to know what gets you out of bed in the morning, or more specifically Why and How You Hack!

Over the next month, we will be posting these interviews on our blog + sending them out to our mailing list.

Thanks in advance for your thoughts!

@stefl
stefl / avatar-caching
Created May 10, 2013 11:21
Use memcache on repetitive avatar requests in Rails
def avatar(options = {})
key = "avatar-#{nickname}-#{options.map {|k,v| "#{k}:#{v}" }.join("-")}"
cached_avatar = Rails.cache.fetch(key)
return cached_avatar if cached_avatar
options.reverse_merge!({size: 48})
unless model.nil?
avatar = h.link_to(h.person_path(model)) do
h.image_tag(avatar_address,
class: 'avatar__img',
data: { src: avatar_address },
@stefl
stefl / gist:5322519
Last active December 15, 2015 20:59
The names of the data sets that #nhtg13 have provided. All 9374 of them
["1-1-5m-scale-geology-through-climate-change-poster-map-covering-uk-mainland-northern-ireland-an",
"1-1056-scale-town-plans-1848-1939",
"1-50-000-scale-gazetteer",
"1-500-scale-town-plans-1848-1939",
"1-50000-scale-gazetteer",
"1-528-scale-town-plans-1848-1939",
"10k-sheet-data-files",
"13-butadiene-running-annual-mean-at-automatic-sites-comparison-with-health-objective-for-2003-u-2010",
"15th-percentile-house-prices-land-registry",
"1987-ongoing-met-office-marine-automatic-weather-station-maws-meteorological-observations",
@stefl
stefl / gist:5143269
Created March 12, 2013 14:24
Weird "localhost" oddness
/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 lvh.me
@stefl
stefl / foundation_paginate.rb
Last active December 13, 2015 20:48 — forked from mariszin/foundation_paginate.rb
Zurb Foundation now uses 'current' instead of 'active' for the active page.
# Based on https://gist.github.com/1182136 and https://gist.github.com/1586384
# Make the will_paginate generate markup for Zurb Foundation
# Put this in config/initializers/foundation_paginate.rb
module WillPaginate
module ViewHelpers
class LinkRenderer < LinkRendererBase
protected
def html_container(html)
tag(:ul, html, container_attributes)
@stefl
stefl / gist:4540506
Created January 15, 2013 17:56
Contenteditable hover and focus states
[contenteditable]:hover:after {
content: ' click to edit';
font-style: italic;
font-size: 12px;
color: #ccc;
}
[contenteditable]:hover, [contenteditable]:focus {
background: #FFFFD3;
}
@stefl
stefl / gist:2385517
Created April 14, 2012 16:17
Rails button_to helper using a button tag rather than an input tag
def button_to_with_button_element(name, options = {}, html_options = {})
fragment = ::Nokogiri::HTML.fragment(button_to(name, options, html_options))
fragment.css("input[type=submit]").each do |input|
input.replace ::Nokogiri::HTML.fragment("<button class='#{input.attribute("class")} type='submit'>#{input.attribute("value")}</button>")
end
raw fragment.to_html
end