Skip to content

Instantly share code, notes, and snippets.

View vanakenm's full-sized avatar

Martin Van Aken vanakenm

View GitHub Profile
class Doctor < ActiveRecord::Base
has_many :interns
has_many :consultations
has_many :patients, through: :consultations
validates :last_name, presence: true
validates :first_name, presence: true
end
@vanakenm
vanakenm / killpumas.sh
Created March 31, 2016 11:07
How to kill your servers
ps -ax | grep puma
# Example result:
27212 pts/3 Sl+ 0:03 puma 3.2.0 (tcp://localhost:3000) [maily-restaurants]
27249 pts/3 Sl+ 0:04 puma: cluster worker 0: 27212 [maily-restaurants]
29574 pts/3 Sl+ 0:01 puma: cluster worker 1: 27212 [maily-restaurants]
32569 pts/9 S+ 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=.cvs --exclude-dir=.git --exclude-dir=.hg --exclu
# Any line that starts with "puma" is a running server. To kill them, take their id and use the "kill" command:
<h1>Header</h1>
<h2 id="subheader">Subheader</h2>
<p>Paragraph</p>
<h2 id="subheader-2">Subheader 2</h2>
<h3 id="subsubheader-1">Subsubheader 1</h3>
connection.dialect = org.hibernate.dialect.H2Dialect
connection.driver_class = org.h2.Driver
connection.url = jdbc:h2:./database/dhis2;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
connection.username = sa
connection.password =
@vanakenm
vanakenm / seeds.rb
Last active December 27, 2017 13:58
EffinSeed
EffinQuote.create([
{
contents: "good luck with your bullshit",
url: "https://pbs.twimg.com/media/DQ2tB-xWkAAKKJh.jpg"
},
{
contents: "got it you're dim",
url: "https://pbs.twimg.com/media/DQ117aPW4AEmnWF.jpg"
}
])
class EffinQuote < ApplicationRecord
include PgSearch
pg_search_scope :search_by_word, against: [:contents]
def self.find_by_word(word)
complete.search_by_word(word).first
end
def self.find_or_random(text)
quote = EffinQuote.find_by_word(text)
quote ? [quote, false] : [EffinQuote.complete.sample, true]
end
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV('TWITTER_CONSUMER_KEY')
config.consumer_secret = ENV('TWITTER_CONSUMER_SECRET')
config.access_token = ENV('TWITTER_ACCESS_TOKEN')
config.access_token_secret = ENV('TWITTER_ACCESS_TOKEN_SECRET')
end
tweets = client.get_all_tweets('effinbirds')
tweets.each do |t|
next unless t.media && t.media.first && t.media.first.uri
image_url = t.media.first.media_uri
tweet_url = t.uri
next if EffinQuote.find_by(url: image_url.to_s)
EffinQuote.create(url: image_url.to_s, twitter_url: tweet_url.to_s)
end
{
"requests": [
{
"features": [
{
"type": "LABEL_DETECTION"
}
],
"image": {
"source": {
def autocomplete
require "google/cloud/vision"
vision = Google::Cloud::Vision.new(project_id: "effin-bot")
image = vision.image(url)
text = image.text.to_s
text = text.gsub("\n", " ").downcase
self.contents = text
save