Skip to content

Instantly share code, notes, and snippets.

View richhollis's full-sized avatar

Richard Hollis richhollis

View GitHub Profile
@richhollis
richhollis / dropbox-monit
Last active May 11, 2016 14:33
Shell script for monit to launch dropbox daemon with ionice idle priority and cpu limit 20%
check process dropbox with pidfile /home/username/.dropbox/dropbox.pid
start program = "/home/username/.dropbox-dist/dropboxd-nice"
as uid username and gid username
stop program = "bin/bash -c '/bin/kill -9 `cat /home/username/.dropbox/dropbox.pid`'"
as uid username and gid username
# an example, showing how to load for rspec and conditionally load for cucumber
# lives in whichever dir you set the other file to load
module ImageStepHelpers
def page_should_contain_image_link_for(image)
page.should have_xpath(%Q(//img[@src="#{image.url}"]))
end
def image_data_from_file(image)
image_file_path = Rails.root.join image.image.path
<!DOCTYPE html>
<html>
<head>
<title>test-vticker</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://sdepold.github.io/jquery-rss/src/jquery.rss.js"></script>
<script src="http://richhollis.github.com/vticker/downloads/jquery.vticker.min.js?v=1.14"></script>
<script>
$(function() {
@richhollis
richhollis / gist:7614183
Created November 23, 2013 12:39
Clojure Week 3 Homework - Poker hand
(defn deck []
(for [suit [:clubs :hearts :spades :diamonds]
pip (range 2 15)]
{:suit suit
:pip pip}))
(defn hand-frequencies [hand]
(frequencies (map :pip (hand))))
(defn n-of-a-kind?
@richhollis
richhollis / gist:7563637
Last active December 28, 2015 21:19
Clojure GitHub API Homework
(ns crash-course-github
(:require [clj-http.client :as http]
[cheshire.core :refer [parse-string]]
[clojure.pprint :refer [pprint]]))
(use 'crash-course-github)
(defn query-github
"Run an arbitrary query against Github API."
[query]
@richhollis
richhollis / gist:7548877
Last active December 28, 2015 19:18
Crash course in Clojure - Week 1 Homework
(require 'crash-course-clojure.spotify)
(use 'crash-course-clojure.spotify)
(def tracks
(love :tracks)
)
(def tracks-sorted
(sort (fn [x y] (> (count(x :name)) (count(y :name)))) tracks)
)
tables = [] # or ActiveRecord::Base.connection.tables
collation = "utf8_unicode_ci"
char_set = "utf8"
db = "your_database_name"
# write out
puts "USE #{db};"
puts "ALTER DATABASE #{db} CHARACTER SET #{char_set} COLLATE #{collation};"
tables.each do |t|
puts "ALTER TABLE #{t} CHARACTER SET #{char_set} COLLATE #{collation};" # changes for new records
puts "ALTER TABLE #{t} CONVERT TO CHARACTER SET #{char_set} COLLATE #{collation};" # migrates old records
import SimpleHTTPServer
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied
to the outputfile by the caller unless the command was HEAD,
and must be closed by the caller under all circumstances), or
# controllers/api/api_controller.rb
class Api::ApiController < ApplicationController
respond_to :json
before_filter :ensure_user
rescue_from ::ApiException do |exception|
logger.info "ApiException #{exception.inspect}"
render :json => { :errors => { :error => exception.message} }.to_json, :status => 400
-----BEGIN CERTIFICATE-----
MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApyaWNo
aG9sbGlzMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNj
b20wHhcNMTMwNDAyMTEzODA0WhcNMTQwNDAyMTEzODA0WjBBMRMwEQYDVQQDDApy
aWNoaG9sbGlzMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC9lueRqZlS9BWQ
KM2Vt8Ajc7goi4mivw+QfuQTbkk3quGuF/ZFrQuyh/N+GXKJmIt/GPoDphVUOBGo
nDMd10NAIdQzHsOzElTAZi85KonMJ8KUG3JTqnomNFjKtxdVSTyi4COSpSemT6Y1
WglANxXyG2PtUOypsMjdDmDrZ0zx0N/+Ovg5lGh862f6rDQDk1EGsdUAa1E7cGGu
FCIBimJ5t/YX86g0+XedXcMeu8neb7zjIb0TaH5p5N/+hRwWh155kt8EsP9Grz7t