Skip to content

Instantly share code, notes, and snippets.

View entrity's full-sized avatar

Markham Anderson entrity

View GitHub Profile
# Config for PS2 Barracuda 1
# buttons are: X A B Y L2 R2 L1 R1 sel start
COMMON
-X
-dev /dev/input/js0
-thresh -32767 32767 -32767 32767 -32767 32767 -32767 32767 -32767 32767 -32767 32767
-axis Left Right Up Down Left Right Up Down Left Right Up Down
-buttons S X Z A D C D C ShiftR Return
@entrity
entrity / Brighten.md
Last active January 12, 2016 04:42
Read/write the brightness on my Ubuntu 14.04 LTS installation on my ThinkPad 440s.

Convenient CLI and GUI for adjusting the brightness on my Ubuntu installation in my Thinkpad T440

#!/bin/bash
# check for -f flag as first argument; if present, bypass all restrictions
if [[ "$1" == "-f" ]]; then
shift
git-commit "$@"
exit 0
fi
fail()
@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%
@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 / 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 / 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 / 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 / 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