Skip to content

Instantly share code, notes, and snippets.

View entrity's full-sized avatar

Markham Anderson entrity

View GitHub Profile
@entrity
entrity / AVR-makefile-base.mk
Last active December 5, 2022 17:35
An extensible Makefile for AVRs which makes use of the Arduino core and (optionally) Arduino libraries.
### MARKHAM'S NOTES:
# This Makefile includes the Arduino core sources. (Set ARDDIR here:)
ARDDIR = /d/arduino
# You should build a tiny Makefile for each of your projects and just declare a few
# things in it, then include this Makefile in it. Your Makefile should be in the same
# directory as your TARGET file (see below).
#
# Exemplia gratia:
@entrity
entrity / Ruby: Array#search
Last active December 16, 2015 13:59
Ruby: Returns the first matching object in an Array, without iterating all the way through as #select does and without having to first return an index as #index does.
@entrity
entrity / pseudo_date_accessor.rb
Last active December 16, 2015 13:59
Rails: Adds a ::pseudo_date_accessor method to your ActiveRecord::Base models. This can be called to make psuedo-getters and pseudo-setters. (See comments internally in the gist.)
=begin
The purpose of this patch is to make pseudo-date accessor and mutator methods.
So if you have a date field :red_letter on a class MyClass,
calling MyClass::pseudo_date_accessor(:red_letter, prev:true) can generate useful methods
:years_since_red_letter
:years_since_red_letter=
calling MyClass::pseudo_date_accessor(:red_letter, next:true) generates
:years_until_red_letter
@entrity
entrity / Rails: ActionView::Helpers::FormBuilder#date_field
Created April 23, 2013 17:12
Create a #date_field helper in your Rails form builder. It is essentially #text_field, but I ended up using this a lot.
module ActionView
module Helpers
class FormBuilder
# Make a field whose class includes 'date' and whose value can be custom-formatted
def date_field method, options={}
date = self.object.send(method).to_date
options[:value] = options.has_key?(:format) ? date.strftime(options[:format]) : date.to_s
options[:class].is_a?(String) ? options[:class] += ' date' : options[:class] = 'date'
rescue
# Usage:
# curl https://gist.githubusercontent.com/entrity/5462105/raw/..linux-setup.sh | bash
# Installs
# - .gitconfig
# - .ssh/config
# - .bash_aliases
src=https://gist.githubusercontent.com/entrity/5462105/raw
wget -O ~/.gitconfig $src/.gitconfig
@entrity
entrity / Using-sublime-w-better-errors-gem.md
Last active December 17, 2015 09:08
Get the better_errors gem's error pages to link successfully to Sublime Text 2 on Windows

You must do three things to get the better_errors gem's error pages to link successfully to Sublime Text 2 on Windows:

  1. set BetterErrors.editor
  2. build a batch file to reformat the path that better_errors supplies into a Windows file path
  3. make a registry key to handle the protocol 'subl'

Set BetterErrors.editor

In your rails projects initializes directory, add a single file (call it whatever you want; I called it better_errors.rb) whose contents is:

@entrity
entrity / x-editable-n-select2-n-ajax.coffee
Last active December 17, 2015 15:19
Integrate select2's autocomplete (using ajax to get remote options) with x-editable
# Functions to handle integration of x-editable w/ select2 w/ ajax source.
# Usage is as follows:
# <a href='#' id='elem' data-type='select2' data-name='template_id' data-url='/crm/task_builders/4' data-id=4></a>
# <script>
# $('#elem').editableSelect2Templates();
# </script>
do () ->
# Convenience method for adding x-editable + select2 behaviour to an <a>.
# Options include queryUrl, url, params, send, placeholder, allowClear, minimumInputLength, query, data, displayKey
@entrity
entrity / screenrc
Last active December 20, 2015 05:49
screen hardstatus
hardstatus alwayslastline
hardstatus string '%{= kg}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
vbell off
@entrity
entrity / audit_logger.rb
Last active December 22, 2015 11:49
AuditLogger & Helper functions for Rails applications
=begin
Usage:
require 'audit_logger'
class MyClass
include AuditLogger::Helpers
audit_logger_name 'my-class.log'
# It works in instance methods
@entrity
entrity / hosts.bat
Last active December 28, 2015 21:38
Run this file on Windows XP or 7 to add PIC sites to your hosts file
# Run this file with the following:
# curl https://gist.github.com/Vaselinessa/7565683/raw/f175a61e61015276476448f917e914700e68cace/hosts.bat | cmd
@echo off
set output=c:\windows\system32\drivers\etc\hosts
echo %output%
echo. >> %output%
echo # Inserted by Markham's script 20-11-2013 >> %output%