Skip to content

Instantly share code, notes, and snippets.

@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
@the-frey
the-frey / Command Line Twitter
Last active April 3, 2016 04:28
An extension of the Twitter API lesson from Codecademy to create a command line app that accepts user input. The idea is you can just have it open in a tab in Bash while you're doing other things. I actually use this all the time now...!
require 'rubygems'
require 'oauth'
require 'json'
#You will need to add your keys below and your username where indicated inside the method.
CONSUMER_KEY1 = "" #consumer key
CONSUMER_KEY2 = "" #consumer secret
ACCESS_TOKEN1 = "" #access token
ACCESS_TOKEN2 = "" #access secret
@the-frey
the-frey / Python Simple Battleship
Created April 12, 2013 09:38
Adaptation of the single-square Battleship game from the Codecademy Python course to use the setup/game loop pattern favoured by Al Sweigart in his Python games book. Variable board size introduced too.
from random import randint
board = []
print '''
Welcome to Battleship! First, let's set up the board...
'''
board_size = raw_input("What board size do you want to play?")
board_size = int(board_size)
@the-frey
the-frey / Abstract XHR
Last active December 18, 2015 05:09
Abstraction of XHR written as part of Udacity's HTML5 Game course. Kinda neat.
function xhrGet(reqUri, callback, type) {
var caller = this.caller;
var xhr = new XMLHttpRequest();
xhr.open("GET", reqUri, true);
if(type){
xhr.responseType = type;
}
@the-frey
the-frey / Guitar Prototyping
Created July 5, 2013 11:47
Crib sheet for prototyping in JS
function Guitar(make, year, sound){
this.make = make;
this.year = year;
this.sound = sound;
this.playChord = function(){
alert(this.sound);
}
};
var anduril = new Guitar("Fender Squier", 1985, "Brang!");
@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 / pid_wrapper_docker.sh
Last active May 21, 2018 12:13
PID Wrapper for Docker and Monit
#!/bin/bash
# First, create a folder: /var/run/monit
# Then, make sure your user or group owns it: chown user:user /var/run/monit
# USAGE:
# use option one to start or stop
# use option two as the docker name
# use option three as the docker run command it follows '-d' f you are starting a container
#