This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Gmail disable cmd+enter | |
// @namespace [email protected] | |
// @description Disables cmd+enter from sending an email in gmail | |
// @include ^https?:\/\/mail\.google\.com.*$ | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
(function(){ | |
var isMac = unsafeWindow.navigator.oscpu.toLowerCase().contains("mac os x"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cases/helper' | |
require 'support/connection_helper' | |
class HotCompatibilityTest < ActiveRecord::TestCase | |
self.use_transactional_tests = false | |
include ConnectionHelper | |
setup do | |
@klass = Class.new(ActiveRecord::Base) do | |
connection.create_table :hot_compatibilities, force: true do |t| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cases/helper' | |
class HotCompatibilityTest < ActiveRecord::TestCase | |
self.use_transactional_tests = false | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
class ::SolarSystem < ActiveRecord::Base | |
has_many :solid_planets, -> {where(classification: "terrestrial")}, class_name: 'Planet' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A helper module to be included in any class that requires a configuration | |
# hash. | |
# | |
# The rationale is that after a while, adding configuration options as columns | |
# on a model becomes unwieldy, especially if there are very many configuration | |
# options but only a few used by each record, this results in lots of nil columns | |
# and is not very flexible. Also it requires migration the database for each new | |
# option. | |
# | |
# This module comes with a method called configuration_accessors that defines virtual attributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import [javax.naming Context InitialContext]) | |
(def development-db-string "postgresql://localhost:5432/foobar_db") | |
(def db-uri | |
(atom | |
(try | |
(. (. (InitialContext.) lookup "java:comp/env") lookup "DATABASE_URL") ; will pull environment variables from a Tomcat server | |
(catch javax.naming.NoInitialContextException e | |
(or |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name anti key-grabber | |
// @description Prevent web apps from capturing and muting vital keyboard shortcuts | |
// @grant none | |
// @version 1.1 | |
// ==/UserScript== | |
(function(){ | |
var isMac = unsafeWindow.navigator.oscpu.toLowerCase().contains("mac os x"); | |
unsafeWindow.document.addEventListener('keydown', function(e) { | |
if (e.keyCode === 116) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; create the client with a twitter.api streaming method | |
(def stream (twitter-client/create-twitter-stream twitter.api.streaming/statuses-filter | |
:oauth-creds twitter-creds | |
:params {:follow user-id})) | |
(defn create-tweet-entities [twitter-tweet] | |
; the entirety of this method should be wrapped in a database transaction | |
(insert stream-tweets | |
(values (twitter-tweet-to-stream-tweet twitter-tweet)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.tokenize_spanish(text) | |
text = text.sub(/(https?:\/\/[\S]*[$\z\s])/i, '') # strip urls | |
words = text.scan(/[\w@#ñÑáÁéÉíÍóÓúÚü]+/) # tokenize into words | |
words.map! {|word| word.downcase} # lowercase everything | |
words.reject! {|word| word.length < 4} # reject words with 3 or fewer characters | |
return words | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# recursively looks up a URL and returns a unicode | |
def self.lookup_url(uri_str, limit = 10, old_uri = nil) | |
raise ArgumentError, 'too many HTTP redirects' if limit == 0 | |
response = Net::HTTP.get_response(URI(uri_str)) | |
case response | |
when Net::HTTPSuccess then | |
return self.unicode_parse(old_uri) | |
when Net::HTTPRedirection then | |
location = response['location'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twitter' | |
client = Twitter::REST::Client.new do |config| | |
config.consumer_key = "xxx" | |
config.consumer_secret = "yyy" | |
config.access_token = "123-zzz" | |
config.access_token_secret = "www" | |
end | |
NewerOlder