Skip to content

Instantly share code, notes, and snippets.

View kaplas's full-sized avatar

Jouni Kaplas kaplas

View GitHub Profile
@kaplas
kaplas / backbone-amd.js
Created May 14, 2013 17:18
How to get Backbone, Underscore (with your own extensions) and RequireJS to work together.
// Use the version from Backbone AMD repository:
// https://github.com/amdjs/backbone
@kaplas
kaplas / read-also-these.txt
Last active December 17, 2015 06:59
Google analytics tester for generating page hits programmically
About the data delay:
https://support.google.com/analytics/answer/1009219?hl=en
@kaplas
kaplas / _rem.scss
Last active December 17, 2015 06:18
A quick SASS helper function and mixin to calculate rem values and px fallbacks for it
@function strip-units($number) {
@return $number / ($number * 0 + 1);
}
@function rem($x, $fallback:false){
@if type-of($x) != "number" or $x == 0 {
@return $x;
} @else {
@kaplas
kaplas / jolt-gist.js
Created May 3, 2013 20:23
valueAndValidFrom, a helper method for creating a pair of value and validity streams from a single RxJS Observable stream. Rocks the world, at least ours.
function notEmpty(val) {
return !_.isEmpty(val);
}
function valueAndValidFrom(observable, validator) {
validator = validator || notEmpty;
return {
valueS: observable.filter(validator),
validS: observable.map(validator)
};
@kaplas
kaplas / code.js
Created May 3, 2013 14:04
Download a file with "AJAX" kind of POST request.
function downloadPDF(expenseClaim) {
var payload = JSON.stringify( expenseClaim );
var input = $("<input />").attr('type', 'hidden').attr('name', 'json').attr('value', payload);
var form = $("<form />").attr('method', 'POST').attr('action', context+'/generatepdf2');
form.append(input);
form.submit();
}
pdfCommandS.subscribe(downloadPDF);
@kaplas
kaplas / combinedMappedStreamBasedOn.js
Last active December 16, 2015 22:29
Helper method for combining latest values from different RxJS observable streams into a new stream based on a JS object template.
// construct function copied from
// http://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible/#1608546
function construct(constructor, args) {
function F() {
return constructor.apply(this, args);
}
F.prototype = constructor.prototype;
return new F();
}
@kaplas
kaplas / gist:5195720
Created March 19, 2013 12:33
Some snippets to get node modules to work better under Windows
for /f "delims=" %a in ('npm bin') do @set NODEBINPATH=%a
set PATH=%PATH%;%nodebinpath%
private Image scaleImage(Image sourceImage, int newImageWidth, int newImageHeight){
// width of original source image
int srcWidth = sourceImage.getWidth();
// height of original source image
int srcHeight = sourceImage.getHeight();
// An array for RGB, with the size of original image)
int rgbSource[] = new int[srcWidth*srcHeight];
// An array for RGB, with the size of scaled image)