Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
@amiel
amiel / aurora-forecast.sh
Created August 19, 2022 22:58
Aurora Forecast for Fairbanks, AK
#!/bin/bash
# This takes the maximum forecast between four points surrounding Fairbanks, AK.
# Paste this in to https://geojson.io/#map=9/64.5053/-147.4997 to see what those points are.
# { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ -147, 65 ]}, "properties": {} }, { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ -147, 64 ]}, "properties": {} }, { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ -148, 65 ]}, "properties": {} }, { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ -148, 64 ]}, "properties": {} } ] }
JQ=$(cat <<-JQ
{
forecast_time: ."Forecast Time" | fromdateiso8601 | strflocaltime("%H:%M (%Z)"),
@amiel
amiel / application_decorator.rb
Created November 3, 2011 22:41
Some handy I18nization for my ApplicationDecorator
class ApplicationDecorator < Draper::Base
# See +ApplicationDecorator.humanize+
def humanize(attribute, key = model.send(attribute), default = key.to_s.humanize)
self.class.humanize attribute, key, default
end
# By default, humanize the attributes listed.
#
# Contrived Example:
@amiel
amiel / my_uploader.rb
Created May 22, 2012 20:51
Simple watermarking with Thumbkit and CarrierWave
class MyUploader < CarrierWave::Uploader::Base
include Thumbkit::Adapters::CarrierWave
# Watermark should always be processed after thumbkit, ensuring that we always
# have a valid image and we don't need to change the extension
def watermark(watermark_image, options = {})
cache_stored_file! if !cached?
Watermarker.new(current_path, watermark_image).watermark!(options)
end
@amiel
amiel / README.md
Created October 28, 2011 19:08
post-commit git hook for simple deploys

Put the ruby file in .git/hooks/post-commit

Create a deploy script as .deploy_*

Example:

# File: .deploy_production
scp -R html example.com:public_html

Then use "deploy *" in your commit message.

@amiel
amiel / my-controller.js
Created May 8, 2014 01:49
ember-validators with server validation errors
MyController = Ember.Controller.extend({
actions: {
save: function() {
this.get('model').save().then(function() {
// Success, maybe transitionToRoute or whatever
}, function(xhr) {
// Oh noes, we had an error, maybe it's a validation error
if (xhr.status == 400) {
$.parseJSON(xhr.responseText).each(function(attribute, errors) {
this.get('errors').set(attribute, errors);
@amiel
amiel / gist:7793267
Last active December 30, 2015 06:59
# LineItemsController
categories: (->
@get('model').mapBy('category').uniq().map (category) =>
Ember.Object.create
name: category
line_items: @get('model').filterBy 'category', category
).property('@each.category')
module ABTestHelper
def test
yield
end
def variant(variant)
if variant_matches(variant)
yield
end
end
@amiel
amiel / _readme.md
Last active December 25, 2015 13:19 — forked from svenfuchs/_readme.md

Based on Mislav's gist, svenfuch's gist and vim-tmux-navigator.

My goal was to allow svenfuch's zoom feature to work in any direction. The original implementation relied on pane numbers, which works when you only split in one direction (either only horizontal or only vertical, but not both).

The logic is simple: use a panes width, height, x, and y along with the width width and height to determine if a pane is the top, bottom, leftmost, or rightmost pane. The reason I switched to ruby is that getting the panes x and y requires parsing the window_layout string.

module Draper
- begin
- require 'minitest/rails'
- rescue LoadError
- end
-
- active_support_test_case = begin
- require 'minitest/rails/active_support' # minitest-rails < 0.5
- ::MiniTest::Rails::ActiveSupport::TestCase
@amiel
amiel / line_items.handlebars
Created October 2, 2013 18:32
grouping items in an Ember.ArrayController
<table>
{{#each category in categories}}
<thead>
<tr>
<th class="large">
{{category.name}}
</th>
</tr>
<tr>
<th>Line Item</th>