Skip to content

Instantly share code, notes, and snippets.

@dancek
dancek / gist:4655893
Created January 28, 2013 14:24
Reusable jQuery UI Dialog that creates a Deferred and returns a promise.
<div id="confirmation" title="Confirm action" style="display: none;">
<p>Are you sure?</p>
</div>
<script>
/* Reusable dialog with deferreds
*
* Example:
* $.modalConfirmation()
* .then(function() { console.log('success'); })
@dancek
dancek / dl-test.js
Last active December 14, 2015 22:48
Download testing
var $container = $('#svg-container'),
// Canvg requires trimmed content
content = $container.html().trim(),
canvas = document.getElementById('svg-canvas');
// Draw svg on canvas
canvg(canvas, content);
// Change img be SVG representation
var theImage = canvas.toDataURL('image/png');
@dancek
dancek / highcharts-exporting_fix-exporting-chartoptions.diff
Created May 24, 2013 12:24
fix for Highcharts export module: exporting.chartOptions
diff --git a/vendor/exporting.src.js b/vendor/exporting.src.js
index d75f7da..75489a2 100644
--- a/vendor/exporting.src.js
+++ b/vendor/exporting.src.js
@@ -335,13 +335,15 @@ extend(Chart.prototype, {
exportChart: function (options, chartOptions) {
options = options || {};
var chart = this,
chartExportingOptions = chart.options.exporting,
@dancek
dancek / ColumnRangeSeries.js
Created June 19, 2013 12:34
Highcharts columnrange with minPointLength support (fix for https://github.com/highslide-software/highcharts.com/issues/1448 )
/**
* The ColumnRangeSeries class
*/
defaultPlotOptions.columnrange = merge(defaultPlotOptions.column, defaultPlotOptions.arearange, {
lineWidth: 1,
pointRange: null
});
/**
* ColumnRangeSeries object
@dancek
dancek / gist:7277624
Created November 2, 2013 10:39
Playing around with the idea of function annotations in Coffeescript
ㅡid = (f) -> f
ㅡmemoize = (f) ->
window._vals = {}
(args...) ->
_args = args.join 'ㅡ'
if _args of _vals
return _vals[_args]
val = f args...
_vals[_args] = val
@dancek
dancek / gist:7354053
Created November 7, 2013 12:47
Given an angular module _r, this is a directive for obfuscating an email address. Would be easy to parameterize and release as a module.
_r.directive 'obfuscateEmail', ->
scope:
email: '='
link: (scope, element) ->
rnd = Math.random().toString(36).substr(2,3)
re = /@/
obfuscated = scope.email?.replace re, "<span class=\"obfuscate\">#{rnd}</span>$&"
element.html obfuscated
@dancek
dancek / gist:7355527
Last active December 27, 2015 16:29
Easy scope value to location mapping with friendly names. Use this inside an angular controller.
# scope to url query part mapping ( #!/?key=val )
queryMapping =
category: 'cat'
searchQuery: 'q'
'selected.id': 'show'
query = $location.search()
for key, queryKey of queryMapping
# initially set scope values to query params
if queryKey of query
$scope[key] = query[queryKey]
@dancek
dancek / gist:9331785
Last active August 29, 2015 13:56
Näppisleiskojen rasittavuuksia suomenkielisille teksteille, pienempi on parempi. Skripti: https://gist.github.com/deekayen/4085169 (muokattu hieman).
justified ~/dev/keylayout-test % php workman.php raamattu1992.txt
QWERTY: 6213088
Asset: 3331671
Capewell: 3662800
Colemak: 3700533
Dvorak: 4309852
Klausler: 3587811
Minimak: 4194483
Norman: 3681826
QGMLWY: 4177042
@dancek
dancek / linebreaks.coffee
Created August 11, 2014 13:26
How different multiline strings behave in CoffeeScript 1.7
a = """<p>
foo
</p>"""
b = '''<p>
foo
</p>'''
c = "<p>
foo
</p>"
d = '<p>
@dancek
dancek / gist:0c52bc9d45beba7ee269
Created May 15, 2015 11:18
Luettelo tyttöjen nimistä, jotka ovat sekä suomalaisessa että suomenruotsalaisessa nimipäiväkalenterissa
Aina
Aino
Alina
Alma
Amalia
Amanda
Anita
Anja
Anna
Anne