Skip to content

Instantly share code, notes, and snippets.

View jnstq's full-sized avatar

Jon Stenqvist jnstq

  • Equipe AB
  • Helsingborg, Sweden
View GitHub Profile
@jnstq
jnstq / installer_controller.rb
Created March 23, 2023 20:09 — forked from adamloving/installer_controller.rb
Rails controller action for an HTML5 cache manifest file.
class InstallerController < ApplicationController
# Rails controller action for an HTML5 cache manifest file.
# Generates a plain text list of files that changes
# when one of the listed files change...
# So the client knows when to refresh its cache.
def cache_manifest
@files = ["CACHE MANIFEST\n"]
@files << 'favicon.ico'
module DeepCompact
def self.blank?(o)
o.nil? || (o.respond_to?(:empty?) && o.empty?)
end
module Array
def deep_compact
map.with_object(self.class.new) { |e, o|
o << (e.respond_to?(:deep_compact) ? e.deep_compact : e)
}.select { |value| !DeepCompact.blank?(value) }
@jnstq
jnstq / HONEYBADGER.mdown
Created August 26, 2017 07:45
Enable honeybadger for javascript on Rails 5.1 when webpacker

Enable honeybadger for javascript using rails-webpacker and cloudfront

Source maps is enabled by default when using rails-webpacker. The rask tasks open the manifest file, post the source map to honeybadger and remove the source map file and remove it from the manifest.

yarn add honeybadger-js

in app/javascript/packs/application.js require honeybadger

var Honeybadger = require('honeybadger-js');
{
"shows": [{
"id": 1,
"name": "Example Show 2016"
}]
}
@jnstq
jnstq / countdown.json
Last active March 12, 2016 08:28
Countdown 128x64
{
"name": "Time",
"style": {
"width": "128px",
"height": "64px",
"background": "black",
"color": "#fff",
"padding": "4px",
"lineHeight": 1.1
},
@jnstq
jnstq / gist:830ec59937ec81de3ed9
Last active August 29, 2015 14:01
Lunchr.io dishes feed format. Lunchr will request the feed at 10:00 every workday.
[ {
"name" : "Bara Rock",
"lat": "",
"lng": "",
"url": "",
"address": "",
"zipcode": "",
"city": "Helsingborg",
"dishes" : [
{
require 'formula'
class Varnish <Formula
url 'http://repo.varnish-cache.org/source/varnish-2.1.5.tar.gz'
homepage 'http://varnish.projects.linpro.no/'
#md5 'd91dc21c636db61c69b5e8f061c5bb95'
depends_on 'pkg-config' => :build
depends_on 'pcre'
@jnstq
jnstq / README.txt
Created February 22, 2012 12:54 — forked from rmm5t/README.md
Locale override examples for the timeago jQuery plugin (http://timeago.yarp.com)
You can represent time statements in most western languages where
a prefix and/or suffix is used.
The default case is to use suffix only (as in English), which you
do by providing the `suffixAgo` and `suffixFromNow` settings in
the strings hash (earlier versions of timeago used the deprecated
`ago` and `fromNow` options). If present, they are used.
2 minutes [suffixAgo]
2 minutes [suffixFromNow]
@jnstq
jnstq / mad_application_mailer.rb
Created January 25, 2012 15:02
MadApplicationMailer
# encoding: UTF-8
require 'render_anywhere'
class MadApplicationMailer
include RenderAnywhere
attr_accessor :options, :body_options
def self.method_missing(name, *args, &blk)
if name.to_s =~ /^deliver_(\w+)$/
perform_delivery($1, *args)
#Taken from http://coderrr.wordpress.com/2008/04/22/building-the-right-class-with-sti-in-rails/
class GenericClass < ActiveRecord::Base
class << self
def new_with_cast(*a, &b)
if (h = a.first).is_a? Hash and (type = h[:type] || h['type']) and (klass = type.constantize) != self
raise "wtF hax!!" unless klass < self # klass should be a descendant of us
return klass.new(*a, &b)
end