Skip to content

Instantly share code, notes, and snippets.

@the-frey
the-frey / fuseki_export.rb
Created May 29, 2014 09:59
Rakefile for a Rake task that will download all named graphs from Fuseki and upload to Stardog.
require 'uri'
require 'rest_client'
class DatabaseDetails
attr_accessor :database_name, :username, :password, :port
def initialize(database_name, username = nil, password = nil, port = nil)
@database_name = database_name
@username = username || 'admin'
@password = password || 'admin'
@the-frey
the-frey / single_file_upload.rb
Created May 29, 2014 10:02
Rake task (needs to be included in the same Rakefile as fuseki_export.rb) to upload a single specified file from a backed up data folder.
task :upload_single_file do
# database connections
fuseki = FusekiConnection.new('glasgow-development', nil, nil, 3030)
stardog = StardogConnection.new('glasgow-development')
file = File.read("#{FusekiExport.template_app_root}/data_backup/postcodes.ttl")
graph_uri_string = "http://linked.glasgow.gov.uk/graph/postcodes"
# begin transaction with basic Stardog superuser creds
begin_transaction_response = RestClient.post "http://#{stardog.username}:#{stardog.password}@localhost:#{stardog.port}/#{stardog.database_name}/transaction/begin", {:accept => :text}
@the-frey
the-frey / docker_top_wrapper_for_monit.sh
Last active August 29, 2015 14:05
A wrapper for the docker top command allowing the exit status to be passed to monit.
#!/bin/bash
# This script originally took an argument passed to it, interpreted that as the docker to attach to, and called docker top on it.
# Unfortunately, monit does not support args for scripts: https://lists.nongnu.org/archive/html/monit-general/2012-11/msg00039.html
# As such, you'll need one of these per container.
sudo docker top <container-name>;
exit $?;
@the-frey
the-frey / monit_block_for_docker_top
Last active August 29, 2015 14:05
A monit program check block that asynchronously looks for a container and calls docker top on it.
# Async program checks using docker top wrapper script
# e.g. to check the status of a container named mongodb each cycle
# check program mongodb with path "/etc/monit/monit_mongodb_docker_top.sh"
check program <docker-container-name> with path </path/to/wrapper/script>
if status != 0 then alert
@the-frey
the-frey / simpledeploy.sh
Created August 19, 2014 14:33
A simple deploy script for a single Docker container
#!/bin/bash
# Arg 1 is user
# Arg 2 is server
# Arg 3 is password
# Arg 4 is docker command to run
# e.g. ./simpledeploy.sh 'alex' 'build.example.com' 'foo' 'sudo docker run -d --name new-memcached alex/memcached'
# if you wanted to see docker ps at the end of the script, you could do: echo "sudo docker ps" >> ./tmp/deploy_command.sh
echo $4 > ./tmp/deploy_command.sh
@the-frey
the-frey / list_mbox_files.clj
Last active August 29, 2015 14:22
List all mbox files in a PST Converter Pro dump
;; very lightly adapted from http://rosettacode.org/wiki/Walk_a_directory/Recursively#Clojure
;; run in the lein repl as it will cause emacs to go sad face
(use '[clojure.java.io])
(defn walk [dirpath pattern]
(doall (filter #(re-matches pattern (.getName %))
(file-seq (file dirpath)))))
;; print all the paths
@the-frey
the-frey / Dev requirements (draft)
Last active August 29, 2015 14:25
Dev requirements (draft)
1. For a project, can pull down and provision other services in one (or a small number of) lines
2. Can make sure that each member of the team is using the same version of these services
3. Can revert to or specify specific versions of services (e.g. for debugging, pairing etc)
4. Should have repeatable configuration that's easy to set up and needs little to no updating
5. Can make sure CI can provision using these versions in the same way and run tests, etc
6. Ideally should also be a simple way of starting these services, stopping them, getting logs for debugging, etc
7. Should not disrupt workflow of developers on the codebase (e.g. lots of extra mental overhead, extra steps to commit code, etc)
8. Should be easy to maintain going forward; crucially, should be difficult to break
9. Should be easy for developers to repackage a build, outside of jenkins
10. Should be able to get Jenkins to build staging versions of all the sites
@the-frey
the-frey / Test for writing post page
Created January 30, 2013 18:51
Sort of a very rough prototype for the review fields in the app.
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
<style type="text/css">
textarea#text {
outline: none;
border:none;
@the-frey
the-frey / tweet
Created February 21, 2013 14:10
A simple program to tweet from the command line. Assuming like me you call this file tweet.rb, simply use: ruby tweet.rb to run. The structure is taken from the Codecademy Twitter API track - check it out, it's pretty cool.
require 'rubygems'
require 'oauth'
require 'json'
#install the above dependencies with rubygems -
#gem install dependency
#You will need these for OAuth. The second of each should be your secret value. The naming simply refects the order in the two OAuth class constructors. Create an app in the Twitter dev centre to get these values, making sure you select the option for 'read and write access'.
CONSUMER_KEY1 = "" #consumer key
CONSUMER_KEY2 = "" #consumer secret
@the-frey
the-frey / checktweets
Last active December 14, 2015 01:59
Again inspired by the Codecademy Twitter API lesson, this is a way of checking Tweets that mention you via the command line (assuming you have set up an app for this very purpose). Pretty simple stuff, pretty-prints the response too.
require 'rubygems'
require 'oauth'
require 'json'
#You will need these for OAuth. The second of each should be your secret value. The naming simply refects the order in the two OAuth class constructors.
CONSUMER_KEY1 = "" #consumer key
CONSUMER_KEY2 = "" #consumer secret
ACCESS_TOKEN1 = "" #access token
ACCESS_TOKEN2 = "" #access secret