Skip to content

Instantly share code, notes, and snippets.

@sankage
sankage / dice.js
Last active July 9, 2018 02:17
D&D dice rollers
window.Dice || (window.Dice = {});
Dice.roll = function(dice) {
let match = /(\d+)?d(\d+)(?:\+(\d+))?/.exec(dice);
if (match == null) {
return {};
}
let number_of_dice = match[1] == undefined ? 1 : parseInt(match[1], 10);
let dice_size = parseInt(match[2], 10);
let modifier = match[3] == undefined ? 0 : parseInt(match[3], 10);
@sankage
sankage / countdown.coffee
Created December 10, 2013 21:21
a countdown clock
countdown = (eventdate, form) ->
cid = -1
start = ->
cid = setInterval update, 500
stop = ->
clearInterval cid
pad = (number, width = 2, z = '0') ->
number = "#{number}"
if number.length >= width
number
@sankage
sankage / images_as_checkboxes.coffee
Last active December 28, 2015 08:38
images as checkboxes
class ImagesAsCheckboxes
constructor: (question_id, conditions = null) ->
@conditions =
debug: conditions && conditions['debug'] || false
exclusive: conditions && conditions['exclusive'] || false
randomize: conditions && conditions['randomize'] || false
grid: conditions && conditions['grid'] || false
static_last: conditions && conditions['static_last'] || false
selector = "span[id^=#{question_id}C]"
@question_id = question_id
jQuery(document).ready(function($){
$.fancybox.open([
{
content : '<a id="ccfa_lander" href="http://ccteamchallenge.force.com/halfmarathon" target="_blank"><img src="<INSERT IMAGE URL HERE>" height="461" width="600"></a>'
}
], {
padding : 0
});
$('#ccfa_lander').click(function(event){
@sankage
sankage / bundle-fail.sh
Created May 23, 2013 13:58
bundle install fail
$ bundle install --path vendor/gems --binstubs
Fetching source index from https://rubygems.org/
Using rake (10.0.3)
Using i18n (0.6.2)
Using multi_json (1.6.1)
Using activesupport (3.2.12)
Using builder (3.0.4)
Using activemodel (3.2.12)
Using erubis (2.7.0)
Using journey (1.0.4)
@sankage
sankage / Bundle Install
Last active December 17, 2015 08:19
Jekyll Testing { rbenv 0.4.0 } { ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0] }
➜ bundle install
Fetching gem metadata from https://rubygems.org/.......
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.0.4)
Installing RedCloth (4.2.9)
Using i18n (0.6.1)
Using multi_json (1.7.3)
Using activesupport (3.2.13)
Using addressable (2.3.4)
@sankage
sankage / SegFault
Created January 28, 2013 04:59
Segmentation Fault when running a failing rspec test.
$ bundle exec rspec spec/features/deleting_leagues_spec.rb
~/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/better_errors-0.3.2/lib/better_errors/core_ext/exception.rb:9: [BUG] Segmentation fault
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
-- Control frame information -----------------------------------------------
c:0061 p:---- s:0168 b:0168 l:000167 d:000167 CFUNC :callers
c:0060 p:0072 s:0165 b:0165 l:001870 d:0015a0 LAMBDA ~/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/better_errors-0.3.2/lib/better_errors/core_ext/exception.rb:
c:0059 p:---- s:0162 b:0162 l:000161 d:000161 FINISH
c:0058 p:---- s:0160 b:0160 l:000159 d:000159 CFUNC :new
@sankage
sankage / CodeTV::highlight_watched
Created November 26, 2012 02:04
CodeTV - Mark watched videos bookmarklet
javascript:(function(){var div,filler,link,names,video,videos,_i,_j,_len,_ref,__slice=[].slice,__indexOf=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};if(localStorage&&localStorage.getItem("watched_videos"))for(div='<div class="course-progress" data-width="100%" style="width: 100%;z-index: 0;"></div>',names=localStorage.getItem("watched_videos").split("|"),videos=$(".bucket-media"),_i=0,_len=videos.length;_len>_i;_i++)video=videos[_i],_ref=video.href.split("/"),filler=_ref.length>=2?__slice.call(_ref,0,_j=_ref.length-1):(_j=0,[]),link=_ref[_j++],__indexOf.call(names,link)>=0&&$(video).before(div)})();
@sankage
sankage / prime.coffee
Created June 23, 2012 21:39
Prime Numbers
class Prime
constructor: (@prime = 2) ->
@history = [@prime]
isPrime: (num) ->
result = true
if num isnt 2
if num % 2 is 0
result = false
else