Skip to content

Instantly share code, notes, and snippets.

@namelessjon
namelessjon / diary.sh
Created March 20, 2020 17:55
Simple script that manages my diary
#!/usr/bin/sh
cd $HOME/Documents/diary
vim -c 'set spell' -c 'hi SpellBad cterm=underline,bold' '+normal Go' diary.md
git add .
git commit --message "Diary $(date +%Y-%m-%d)"
@namelessjon
namelessjon / plot_temp.R
Last active May 27, 2018 11:46
Code to plot temperature sensor data
library(readr)
library(dplyr)
library(ggplot2)
read_tsv("http://192.168.1.204:8000/temp.log",
col_names = c("Time", "Temp", "Temp (Smooth)"),
col_types = cols(.default = col_double(), Time = col_datetime())) %>%
@namelessjon
namelessjon / exponential_scales.R
Last active February 19, 2020 12:23
Exponential scales in ggplot with tidy labels
# Exponential scales in ggplot with tidy labels
p <- ggplot(data, aes(...))
p <- p + scale_x_log10(
breaks = 10^seq(0, 6, by = 2), # generate breaks every 2 powers of 10, starting at 1
minor_breaks = 10^seq(0, 6),
labels = parse(text = c("1", "100", "10^4", "10^6")) # this makes them pretty
)
@namelessjon
namelessjon / passgen.rb
Created January 28, 2016 13:41
Generate random passwords according to a given pattern
#!/usr/bin/ruby
# Generate random passwords according to guidance in
# https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/458857/Password_guidance_-_simplifying_your_approach.pdf
require 'securerandom'
module PassGen
VOWELS = %w{a i e o u}.map { |l| l.freeze }.freeze
CONSONANTS = (('a'..'z').to_a - VOWELS).map { |l| l.freeze }.freeze
SYMBOLS = ['!', '$', '%', '^', '&', '*', '+', '-', '_', '?', '@', '#', '~', '.', ',', '=', '"', '\\', '/', '<', '>', ':', ';'].map { |l| l.freeze }.freeze
@namelessjon
namelessjon / mounted_server.rb
Last active December 17, 2015 01:09
Combine a rack app with reel, to get the best of both worlds: A rack app (could be sinatra or even rails) for routing and dealing with pure HTTP requests, and all the power of reel and celluloid for dealing with things like websockets.
# Copyright (c) 2013 Jonathan Stott
#
# Permission is hereby granted, free of charge, to any person ob-
# taining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restric-
# tion, including without limitation the rights to use, copy, modi-
# fy, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is fur-
# nished to do so, subject to the following conditions:
#
@namelessjon
namelessjon / gist:5518574
Last active December 17, 2015 00:09
Rough sketch of the internal organisation for game app. Is this kind of thing safe with respect to potentially overlapping calls of the various methods on rooms that might iterate over it while other methods add/delete from it?
class Webapp
include Reel::App
get '/' do
rooms = Actor[:rooms].list_rooms
# serialize and stuff here
end
post '/:room' do
# do some stuff
@namelessjon
namelessjon / planter.rb
Created October 19, 2012 09:27 — forked from ttscoff/planter.rb
Create directory trees from indented text input
#!/usr/bin/ruby
# ruby script to create a directory structure from indented data.
# Three ways to use it:
# - Pipe indented (tabs or 2 spaces) text to the script
# - e.g. `cat "mytemplate" | planter.rb
# - Create template.tpl files in ~/.planter and call them by their base name
# - e.g. Create a text file in ~/.planter/site.tpl
# - `planter.rb site`
# - Call planter.rb without input and it will open your $EDITOR to create the tree on the fly
# You can put %%X%% variables into templates, where X is a number that corresponds to the index
@namelessjon
namelessjon / friendship_example.rb
Created June 10, 2012 10:20
Example of friendships and retriving all records.
#!/usr/bin/env ruby
#
# Example of friendships and retriving all records.
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
# setup the logger
DataMapper::Logger.new($stdout, :debug)
@namelessjon
namelessjon / markdown2html.rb
Created May 16, 2012 10:19
My redcarpet-using script to convert my markdown notes into a html file. Is customised a little to cope with textile sections, making figures, and some basic html entity replacement.
#!/usr/bin/ruby
# Now with a hacky outline too, generated after: http://blog.steveklabnik.com/posts/2011-12-21-redcarpet-is-awesome
filename = ARGV.first
filename = File.basename(filename) if filename
require 'redcloth'
require 'redcarpet'
require 'yaml'
require 'mustache'
@namelessjon
namelessjon / zxcvbn.html
Created April 11, 2012 15:26
hacky little js/html to figure out password entropy with zxcvbn and show password anatomy
<html>
<head>
<title>zxcvbn</title>
</head>
<body>
<h1>pass</h1>
<input />
<dl>
<dt>Entropy</dt>
<dd id='e'>0</dd>