Skip to content

Instantly share code, notes, and snippets.

View kritollm's full-sized avatar

Kristian Tolleshaug Mørch kritollm

View GitHub Profile
@kritollm
kritollm / bulmatoscss_gulpfile.js
Last active December 25, 2018 13:04
Converts Bulma CSS framework from SASS to SCSS
// Bulma to scss gulp script
// In your terminal
// 1. npm install -D sass-convert gulp bulma gulp-sass gulp-replace
// 2. gem install sass
var gulp = require("gulp"),
replace = require('gulp-replace'),
converter = require('sass-convert'),
sass = require('gulp-sass');
@kritollm
kritollm / nodeapptowebjob_gulpfile.js
Last active March 28, 2017 14:05
Gulp script to pack a node app ready for uploading as webjob in azure portal.
const gulp = require('gulp');
const zip = require('gulp-zip');
gulp.task('default', () =>
gulp.src(['**/settings/**/*.json', '**/run.js', '**/app/**/*.js', '**/node_modules/**/*','settings.job'])
.pipe(zip('YOUR_APP_NAME' + (new Date()).toJSON() + '.zip'))
.pipe(gulp.dest(''))
);
// 1.The script assumes your app have some settings stored as .json in a drawer named settings (remove if not, ofcourse).
@kritollm
kritollm / web-animations.d.ts
Last active October 3, 2017 09:06
Typescript definition file for the web animations api, in progress.
// UPDATE: The types is ready. npm install @types/web-animation-js
// I leave this as an refference for the w3c specs
// I coldn't find any definition file. This is a work in progress and it's my first d.ts file so the gist will be updated.
// The latest spec and the latest web-animations-js polyfill isn't compatible, so I will try to make it more web-animations-js compatible.
interface DocumentTimelineOptions {
originTime: DOMHighResTimeStamp;
}
declare type FillMode = "none" | "forwards" | "backwards" | "both" | "auto";
declare type IterationCompositeOperation = "replace" | "accumulate";
@kritollm
kritollm / equalObject.js
Last active March 8, 2017 10:50
Compare objects before storing to firebase db. May not work for objects in arrays (not supposed to either). When jsonEqual would do, but property order is messed up.
var isArray = Array.isArray || function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
function isObject(o) {
return ((o !== null) && (typeof o === 'object') && !isArray(o));
}
function jsonEqual(object1, object2) {
return JSON.stringify(object1) == JSON.stringify(object2);
module.exports = (function (w, prefixes, fnc) {
while (!fnc && prefixes.length) {
fnc = w[prefixes.pop() + 'equestAnimationFrame'];
}
return (fnc && fnc.bind(w)) || w.setImmediate || function (fnc) { setTimeout(fnc, 0); };
})(window || global, ['webkitR', 'mozR', 'msR', 'oR', 'r']);
@kritollm
kritollm / javascriptObjectToCSV.js
Last active September 19, 2016 21:11
Convert array with flat objects to comma separated CSV. Also works with objects where prop(s) is an array with same length in all the objects.
var fs = require('fs');
function arrayToProps(o){
let props = Object.keys(o).forEach(p => {
if(o[p] instanceof Array){
var a = o[p];
delete o[p];
a.forEach((e, i) => (o[p + "_" + i] = e));
}
});
return o;
@kritollm
kritollm / callBackToPromiseWrapper.js
Last active September 10, 2016 10:09
Wrap node style callback functions so it returns a promise.
function promisewrapper(fn) {
return (...args) => {
return new Promise((resolve, reject) => {
args.push((error, body) => {
if (error) {
return reject(error);
}
return resolve(body);
});
fn(...args);
@kritollm
kritollm / angle-between-points.js
Created September 1, 2016 10:55 — forked from conorbuck/angle-between-points.js
JavaScript: Find the angle between two points
var p1 = {
x: 20,
y: 20
};
var p2 = {
x: 40,
y: 40
};