Skip to content

Instantly share code, notes, and snippets.

@callumj
callumj / 1prep.yml
Created July 14, 2014 13:04
Ansible examples
---
# Configures the system for deploying My School Day
- name: Ensure backend directory exists
file: path=/apps/backend state=directory owner=app group=apps mode=0770
- name: Ensure shared directory exists
file: path=/apps/shared state=directory owner=app group=apps mode=0770
- name: Ensure shared sub directories exist

If you import live data into Google Docs spreadsheets using the importdata function and you want to force a refresh at a certain interval, but you also want to ensure that some cache-busting goes on, append a querystring that's the epoch time value that the refresh occurs, so for a sheet that should grab new data every hour you could force an update like this:

importData("http://example.com/data.csv?" & hour(googleclock()) & ")")

But the url requested looks like this: http://example.com/data.csv?11 if the refresh happened at 11am. The next day at 11, the url will be the same, so there's a chance you may get cached data. To get around this, use an epoch time-based refresh. The formula:

=((date(year(googleclock()),month(googleclock()),day(googleclock())) & " " & time(hour(googleclock()), 0, 0)) - DATE( 1970;1;1))*86400

gives you the epoch timestamp for the time at the current hour. If you wanted the timest

@sferik
sferik / and_or.rb
Last active December 31, 2015 14:49
class BasicObject
def &&(other)
other
end
def ||(other)
self
end
end
@pcreux
pcreux / Gemfile
Last active December 11, 2023 20:24
Fast Rails + Heroku Configuration
group :production do
gem 'unicorn'
# Enable gzip compression on heroku, but don't compress images.
gem 'heroku-deflater'
# Heroku injects it if it's not in there already
gem 'rails_12factor'
end
@bokmann
bokmann / JRuby Awesome Performance
Last active August 31, 2023 07:32
brief summary of massive performance improvements with JRuby
# Thee will be more information here when I share the entire problem space I'm working on, but
# in short, this is preview material for my second talk in a series called "What Computer Scientists Know".
# The first talk is on recursion, and goes through several examples., leading up to a problem based
# on a simple puzzle that initial estimates based on performance of a previous puzzle would take years
# to solve on modern computers with the techniques shown in Ruby. That sets the stage for improving the
# performance of that problem with threading, concurrency, and related tuning.
#
# The second talk is on threading and concurrency, touching on algorithmic performance as well.
# Using some knowledge of the problem (board symmetry, illegal moves, etc), we reduce the problem space
# to about .5% of what we initially thought it was. Still, the initial single threaded solution took more
@noprompt
noprompt / word-re.txt
Last active May 2, 2016 15:30
Regular expression for matching any word in `/usr/share/dict/words`.
This file has been truncated, but you can view the full file.
(?:s(?:(?:u(?:b(?:(?:s(?:t(?:a(?:n(?:t(?:i(?:a(?:l(?:(?:i(?:s[mt]|a|ty|ze)|ly|ness))?|t(?:i(?:on|ve)|e|or)|bility)|v(?:e(?:(?:ly|ness))?|al(?:ly)?|i(?:ty|ze))|fy|ous|ze))?|c(?:e(?:less)?|h)|dard(?:ize)?)|lagmit(?:e|ic)|ge|tion)|r(?:a(?:t(?:o(?:s(?:pher(?:e|ic)|e)|r)|i(?:ve)?|al|e|um)|ct(?:ion)?)|uct(?:(?:ion(?:al)?|ur(?:al|e)))?|iate)|itu(?:t(?:i(?:on(?:a(?:l(?:ly)?|ry))?|ng(?:ly)?|ve(?:ly)?)|e(?:[dr])?|able)|ent)|o(?:r(?:eroom|y)|ck)|yl(?:ar|e)|ernal)|e(?:[ta]|r(?:v(?:i(?:en(?:t(?:(?:ly|ness))?|c[ey])|ate)|e)|o(?:sa|us)|ies|rate)|c(?:u(?:t(?:e|ive)|rity)|retar(?:ial|y)|t(?:ion)?|ive)|quen(?:t(?:(?:ial(?:ly)?|ly|ness))?|c[ey])|ns(?:u(?:al|ous)|ation|ible)|pt(?:uple)?|mi(?:fusa|tone)|xtuple|wer|ssile|gment)|i(?:d(?:i(?:ar(?:i(?:e|ly|ness)|y)|z(?:a(?:ble|tion)|e(?:r)?)|ng|st)|e(?:(?:n(?:c[ey]|t)|r))?|y)|st(?:(?:en(?:c[ey]|t(?:ial)?)|ingly))?|l(?:ic(?:ate|ic)|l)|m(?:i(?:lation|ous)|ple)|zar(?:ship)?|nuous)|c(?:ri(?:pt(?:(?:i(?:on(?:ist)?|ve(?:ly)?)|ure))?|b(?:e(?:r(?:ship)?)?|able)|ve(?:r)?)|apular(?:(?:is|y))?|
@txus
txus / function_composition.coffee
Last active December 20, 2015 05:19
Function Composition in Javascript
comp = (fns...) ->
(arg) ->
fns.reverse().reduce((x, fn) ->
fn(x)
, arg)
timesthree = (a) -> a * 3
timestwo = (a) -> a * 2
negative = (a) -> -a
@egonSchiele
egonSchiele / dining.rb
Last active September 22, 2018 12:23
Dining philosophers in Ruby with Celluloid. Modified from https://gist.github.com/bugant/4984042
require 'rubygems'
require 'celluloid'
class Waiter
include Celluloid
FORK_FREE = 0
FORK_USED = 1
attr_reader :philosophers
attr_reader :forks
attr_reader :eating
(function() {
// NOTE: I have intentionally avoided the use of jQuery in
// the next two functions so as not to obscure any details.
// Updates the DOM in such a way that layout is constantly
// computed and thrown away.
var UpdateThrash = function(data) {
// Get all the labels
var spans = document.querySelectorAll('.item .lab');
@bf4
bf4 / ruby_learning.md
Last active July 17, 2021 08:06
Some Ruby Learning Resources