Skip to content

Instantly share code, notes, and snippets.

View walterdavis's full-sized avatar

Walter Lee Davis walterdavis

View GitHub Profile
@madrobby
madrobby / gist:8dc43c58114466d6a894
Created June 24, 2014 12:20
Code to prevent drag/drop in a Webview inside a Mac app. You can throw this in a `<script>` tag first thing inside the `<body>`. Users will no longer be able to accidentally break your app by dropping something (like a web page URL) onto it.
document.addEventListener('dragover', function(e){
e.preventDefault();
e.stopPropagation();
}, false);
document.addEventListener('drop', function(e){
e.preventDefault();
e.stopPropagation();
}, false)
@r38y
r38y / set_time_zone_back.rb
Last active August 29, 2015 14:04
Set timezone method that sets the time zone back after the request
class ApplicationController < ActionController::Base
around_action :set_timezone
def set_timezone
old_time_zone = Time.zone
Time.zone = current_user.time_zone
yield
ensure
Time.zone = old_time_zone
end
@mattwynne
mattwynne / integrated_docs.rb
Created November 21, 2012 00:27
Integrated documentation for Ruby
# For context, this was inspired by the RubyRogues podcast #79 where they talked about
# documentation in Ruby, and specifically grumbled quite a bit about the failings of RDoc.
#
# http://rubyrogues.com/079-rr-documenting-code/
#
# As someone who's spent a lot of time using an IDE for programming C# and Java, I think
# Ruby could do a lot better at putting documentation at our fingertips as we program.
#
# Maybe making the documentation part of the structure of the code would facilitate this?
#
# Requires Ruby 1.9 and OS X
# The letters in your game... include repeats
game_letters = %w()
# Words that have been played already
played = %w()
def to_hash(letters)
letters.inject({}) do |h,l|
h[l] ||= 0
require 'base64'
require 'nokogiri'
module Rack
# Rack middleware to inline css and images from underlying application so it
# can be proccessed by PDFKit without additional network requests.
#
# For example, this middleware will transform this response:
#
# <html>
@r38y
r38y / four_oh_four.rb
Last active December 21, 2015 18:09
Render custom template for 404s
module FourOhFour
extend ActiveSupport::Concern
included do
rescue_from ActiveRecord::RecordNotFound, ActionController::RoutingError, with: :render_404
end
def render_404
render template: 'error_pages/404', status: :not_found, format: [:html] and return false
end
@subimage
subimage / backbone-prototype.js
Last active December 22, 2015 21:19
A Prototype.js => 1.7.1 compatible backbone.js 0.9.1 Used in production for Cashboard (http://cashboardapp.com)
// Backbone.js 0.9.1
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
//
// HACKED TO BE PROTOTYPE.JS COMPATIBLE BY [SUBIMAGE AT GMAIL DOT COM]
// REQUIRES PROTOTYPE >= 1.7.1
@dorkalev
dorkalev / a start
Last active December 23, 2015 08:29
sentence = "there is a wild rose"
letters = sentence.gsub(' ','').split(//)
@nodebotanist
nodebotanist / gist:0b976847f4c68eb389f8
Last active June 16, 2016 19:48
On "Real Coding," history, and what it means to be a programmer.

I'm sitting here, on a rainy Sunday morning in June 2015, in front of my MacBook Air, flipping switches on my Android, staring at the computer. A light bulb in my living room flickers from blue, to orange, to some weird green color. I'm tracking Bluetooth LE Characteristics. I have a Bluetooth light bulb, and they don't have a javascript API yet, so I'm using noble and node to write one.

I'm sitting there, a few miles away, in I want to say August 1999. I'm staring at a CRT monitor, and plugged into a USB port on my family's windows tower is a GameBoy GameShark that I took on a lot of chores and time to earn. plugged into that is some Harvest Moon game or another. I want to say I needed more tomato seeds. My child-brain decided that instead of figuring out a way to earn the in-game currency, I would alter the universe.

I wasn't the most straightforward-thinking kid.

Since then I've learned I could've just used Yahoo (or even Ask Jeeves!) for the codes. Instead I looked up how to make them: I found profanit

@mdesantis
mdesantis / delayed_job_init_script.sh
Last active July 2, 2018 20:07
Delayed Job init script; it uses start-stop-daemon and supports every Ruby version manager (RVM, rbenv, chruby...)
#!/bin/sh
### BEGIN INIT INFO
# Provides: delayed_job
# Required-Start: $all
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the delayed_job instances
# Description: starts the delayed_job server instances using start-stop-daemon
#