Skip to content

Instantly share code, notes, and snippets.

View leemeichin's full-sized avatar
:shipit:

Lee Meichin leemeichin

:shipit:
View GitHub Profile
@leemeichin
leemeichin / README.md
Created April 12, 2012 12:02
Modulo Liquid filter for Jekyll

Modulo Liquid filter for Jekyll

Got nested columns in your grid-based Jekyll site?

Wondered why you didn't have a way to calculate the modulo inside your posts loop to open and close your 'rows' containing those nested columns?

Add this filter to your _plugins directory, and use it like so:

{{ x | mod:y }}
@leemeichin
leemeichin / url_validator.rb
Created July 20, 2012 15:02
Rails Custom URL Validator
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << (options[:message] || "must be a valid URL") unless url_valid?(value)
end
# a URL may be technically well-formed but may not actually be
# valid, so this checks for both.
def url_valid?(url)
url = URI.parse(url) rescue false
url.kind_of?(URI::HTTP) || url.kind_of?(URI::HTTPS)
@leemeichin
leemeichin / README.md
Created October 9, 2012 16:11
Apply Standard Competition Rankings to your leaderboard

Standard Competition Rankings

This class makes it easier to generate a leaderboard that complies with the Standard Competition Ranking system. That is, it takes joint/tied positions into account, and adjusts the positions accordingly.

Take the following list of users and points for example:

User    | Points
1         35
2         35
@leemeichin
leemeichin / mode-line.el
Created November 7, 2012 16:51
Customising your emacs mode-line
;; Sets the default mode-line. Remove '-default' if you want to test your changes on-the-fly with (eval-buffer)
(setq-default mode-line-format
'(
;; add a noticeable red block that says 'READ ONLY' when the file's, er, read only
(:eval
(when (eql buffer-read-only t)
;; propertize adds metadata to text, so you can add colours and formatting, amongst other things
(propertize " READ ONLY " 'face
'(:background "color-88" :foreground "white" :weight bold))))
;; show the buffer filename, with a green background when unmodified/saved and a red one when modified
@leemeichin
leemeichin / sphinx.rb
Last active May 12, 2016 14:06
Sphinx 0.9.9 OS X
require 'formula'
class Libstemmer < Formula
# upstream is constantly changing the tarball,
# so doing checksum verification here would require
# constant, rapid updates to this formula.
head 'http://snowball.tartarus.org/dist/libstemmer_c.tgz'
homepage 'http://snowball.tartarus.org/'
end
@leemeichin
leemeichin / termwidth.kak
Created December 20, 2016 21:12
Break lines at terminal width
hook buffer InsertChar [^\n] %sh{
echo exec -draft "gh<a-k>.{$(tput cols),}<ret><a-;>bi<ret><esc>"
}
return botBuilder(function (req, ctx) {
var date = chrono.parse(req.text)
var yearMonthDay = parseTheDate(date[0].start.date()) # make a YYYY-MM-DD string
var message = new SlackTemplate()
.channelMessage(true)
.replaceOriginal(true)
message.addConfirmation(
'Just double checking!',
"I'm going to look for awesome sauces for *" + date[0].text + '*, is that right?',
var botBuilder = require('claudia-bot-builder')
var chrono = require('chrono-node')
var request = require('request-promise-native')
var SlackTemplate = botBuilder.slackTemplate
mkdir awesome-sauce && cd $_
export AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=...
yarn init
yarn add claudia claudia-bot-builder chrono-node request-promise-native
touch bot.js
yarn run claudia create -- --region us-east-1 --api-module bot
yarn run claudia update -- --configure-slack-slash-command
mkdir tf-liedetector && cd $_
git init
echo "node_modules/" >> .gitignore
yarn init
yarn add claudia claudia-api-builder request-promise-native request pg lodash.find
touch app.js