Skip to content

Instantly share code, notes, and snippets.

View simonlehmann's full-sized avatar

Simon Lehmann simonlehmann

  • Mable
  • Perth, Western Australia
View GitHub Profile
@simonlehmann
simonlehmann / create_labels.sh
Last active September 7, 2016 02:55 — forked from omegahm/create_labels.sh
Create Gtihub labels from Bash
#!/usr/bin/env bash
# Colours picked from https://robinpowered.com/blog/best-practice-system-for-organizing-and-tagging-github-issues/
###
# Label definitions
###
declare -A LABELS
# Platform
@simonlehmann
simonlehmann / forum.rb
Created February 17, 2017 08:39
Loading all users with one of many Rolify roles per scoped resource
Class Forum < ActiveRecord::Base
belongs_to :user
def collaborators
User.with_any_role({ name: :admin, resource: self }, { name: :moderator, resource: self })
end
end
@simonlehmann
simonlehmann / session_store.rb
Created March 1, 2017 03:10
Sign out all Devise users
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_myapp_name_session'
# Change :key (e.g: from _myapp_name_session to _myapp_name_sessions) and all users are logged out after server restart.
@simonlehmann
simonlehmann / ability.rb
Last active February 23, 2018 15:43 — forked from vmarcetic/ability.rb
Rails, Devise, CanCanCan, Rolify and User Group Roles
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # This is used for not logged user if you have a need for it
case user.current_role
when 'admin'
can :manage, :all
@simonlehmann
simonlehmann / progress-bar.coffee
Last active April 6, 2017 07:11
Calculate Bootstrap progress-bar width percentage from aria values
$(document).ready ->
$('.progress-bar').each (i, obj) ->
value = Number($(obj).attr('aria-valuenow'))
range = Number($(obj).attr('aria-valuemax')) - Number($(obj).attr('aria-valuemin'))
percentage = ((value/range) * 100).toFixed(2)
# console.log "Value: #{value}, Range: #{range}, Percentage: #{percentage}"
$(obj).css("width", percentage + '%')
return
return
@simonlehmann
simonlehmann / layout.html
Created May 5, 2017 02:22
Dynamically generated canonical URLs in Jekyll
<link rel="canonical" href="{{ site.url }}{{ page.url | replace:'index.html',''}}">
@simonlehmann
simonlehmann / scrollable_pre.css
Created May 9, 2017 10:41
Scrollable bootstrap <pre> tags
pre {
overflow-x: auto;
}
pre code {
word-wrap: normal;
white-space: pre;
}
@simonlehmann
simonlehmann / nginx.conf
Last active July 20, 2017 07:45
Global catch-all server block for Nginx
html {
[...]
##
# Virtual Host Configs
##
# Default catch-all server block
server {
listen *:80 default_server;
@simonlehmann
simonlehmann / Contract Killer 3.md
Created July 29, 2017 10:30 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@simonlehmann
simonlehmann / wordlist.md
Created October 19, 2017 15:58
Mnemonic Encoding Word List

Mnemonic Encoding Word List

http://web.archive.org/web/20090918202746/http://tothink.com/mnemonic/wordlist.html

  • The wordlist contains 1626 words.
  • All words are between 4 and 7 letters long.
  • No word in the list is a prefix of another word (e.g. visit, visitor).
  • Five letter prefixes of words are sufficient to be unique.
  • The words should be usable by people all over the world. The list is far from perfect in that respect. It is heavily biased towards western culture and English in particular. The international vocabulary is simply not big enough. One can argue that even words like "hotel" or "radio" are not truly international. You will find many English words in the list but I have tried to limit them to words that are part of a beginner's vocabulary or words that have close relatives in other european languages. In some cases a word has a different meaning in another language or is pronounced very differently but for the purpose of the encoding it is still ok - I assume that when the encoding is