Skip to content

Instantly share code, notes, and snippets.

View mkelley33's full-sized avatar
🎯
Focusing

Michaux Kelley mkelley33

🎯
Focusing
View GitHub Profile
@mkelley33
mkelley33 / copy_my_computer_ip.sh
Created June 15, 2012 02:28
Copy computer's IP address to clipboard
# When testing a rails website on my local development machine, I found my
# Parallel's VM wouldn't load 0.0.0.0:3000, 127.0.0.1, or localhost:3000.
#
# So I tried using my computers IP address and voila. I thought I'd hone
# my bash chops a little and extract the IP address with the port number
# concatenated to it. This command puts that on the clipboard so I can just
# paste it into IE so I could browser test.
#
# NOTE: the pbcopy command is Mac specific.
#
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload|
if payload[:exception]
name, message = *payload[:exception]
Uhoh::Failure.create!(:message => message)
end
end
@mkelley33
mkelley33 / gist:4158093
Created November 28, 2012 00:12 — forked from dodecaphonic/gist:946254
Function set sequences to max in Postgres (instead of writing the same piece of code in ruby again and again)
Taken from http://stackoverflow.com/questions/244243/how-to-reset-postgres-primary-key-sequence-when-it-falls-out-of-sync.
--drop function IF EXISTS reset_sequence (text,text) RESTRICT;
CREATE OR REPLACE FUNCTION "reset_sequence" (tablename text,columnname text) RETURNS bigint --"pg_catalog"."void"
AS
$body$
DECLARE seqname character varying;
c integer;
BEGIN
select tablename || '_' || columnname || '_seq' into seqname;
@mkelley33
mkelley33 / clear-form.js
Created November 28, 2012 01:18
Clear form with JavaScript
(function($) {
$.fn.clearForm = function() {
return this.find(':input').each(function() {
switch (this.type) {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
return $(this).val('');
@mkelley33
mkelley33 / clear-coffee-script.coffee
Created November 28, 2012 01:20
Clear form with CoffeeScript
(($) ->
$.fn.clearForm = ->
@find(":input").each ->
switch @type
when "password", "select-multiple"
, "select-one"
, "text"
, "textarea"
$(this).val ""
when "radio", "checkbox"
@mkelley33
mkelley33 / best_in_place_fix.js.coffee
Created December 3, 2012 07:43
best_in_place: fix disappearing line-breaks in textarea
jQuery ->
$('[id^="best_in_place_your_object_"],[id$="address"]').on 'best_in_place:update', (event) ->
$address = $(event.target)
$address.data('bestInPlaceEditor').original_content = $address.html()
$address.html $address.html().replace(/[\n\r]+/g, '<br>')
@mkelley33
mkelley33 / mkelley33-pryrc.rb
Last active December 17, 2015 12:29
My .pryrc
# encoding: UTF-8
Pry.config.editor = "vim"
Pry.config.pager = false
Pry.config.commands.alias_command "lM", "ls -M"
if defined?(Encoding) then
Encoding.default_external = 'utf-8'
Encoding.default_internal = 'utf-8'
else
$KCODE = 'utf-8'
Mongoid.connect_to 'mongoid-3144'
class Post
include Mongoid::Document
field :name
embeds_many :comments
accepts_nested_attributes_for :comments
# This line somehow triggers the bug; commenting it out fixes the bug, wierd.
@mkelley33
mkelley33 / .ackrc
Created March 7, 2014 23:16
My .ackrc
# Always sort the files
--sort-files
# Always color, even if piping to a another program
--color
# Use "less -r" as my pager
--pager=less -r
# File type search options
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE