Skip to content

Instantly share code, notes, and snippets.

View jkarttunen's full-sized avatar

Juha Karttunen jkarttunen

View GitHub Profile
@jkarttunen
jkarttunen / 1_getting_started_with_dev.md
Last active August 29, 2015 14:06
Front End Learning resources

Getting started with front-end development

Books should be available in Siili library, also in dead-trees format. Some of the sites are paywalled but worth it, so prefer these over free copies. If something is missing, please have it bought.

Thinking and concepts

Workflows and tools

  • To get you started without scary tool installs and command line interface, you can use Prepros.io to play with modern web development workflow, packaged in one app.
@jkarttunen
jkarttunen / base64.js
Last active August 29, 2015 14:19 — forked from chrisveness/base64.js
/**
* Encode string into Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648].
* As per RFC 4648, no newlines are added.
*
* Characters in str must be within ISO-8859-1 with Unicode code point <= 256.
*
* Can be achieved JavaScript with btoa(), but this approach may be useful in other languages.
*
* @param {string} str ASCII/ISO-8859-1 string to be encoded as base-64.
* @returns {string} Base64-encoded string.
function assert (actual, expected, msg, su) {
if (!window.assertions) {
window.assertions = {success:0, fail:0};
}
if (expected !== actual) {
var message = msg || 'expected ' + expected + ' but got ' + actual;
console.warn(message);
window.assertions.fail = window.assertions.fail +1
} else {
window.assertions.success = window.assertions.success +1;
@jkarttunen
jkarttunen / findParentTag.js
Last active April 12, 2020 06:54
Find parent tag
/**
* Recursively find parents until matching tag has been found.
* Useful when observing clicks on elements with child elements, but you need to use data- attributes from parent.
* @param {HTMLElement} element - Element to find parent from.
* @param {string} tag - Parent tag to find. Eg. 'DIV' or 'H1'
**/
function findParentTag(element, tag) {
const tagName = tag.toUpperCase();
if (element.tagName === tagName) return element;
@jkarttunen
jkarttunen / getSubdomain.js
Created April 12, 2020 07:19
Get subdomain from hostname
/**
* Extracts subdomain from hostname. Works with localhost, but not with full url with ports.
* @example
* getSubdomain(location.hostname); //www.google.com
* // returns 'www'
* @example
* getSubdomain(location.hostname); //localhost
* // returns 'localhost'
**/
@jkarttunen
jkarttunen / bem.js
Created April 12, 2020 07:26
Simple Bem classname utility
/**
* Stupid simple BEM utility for class names. Useful for creating className strings in simple components
* @param {string} block - Block name
* @param {string} [element] - Element name
* @param {string} [modifier] - modifier name
* @return {string} A BEM string,
*
* @example
* bem('button', 'icon', 'red');
* // returns 'button button--icon button--icon--red'
@jkarttunen
jkarttunen / gulpfile.js
Created April 12, 2020 10:14
Build multiple apps with Create-React-App without ejecting
const { series, src, dest } = require('gulp');
const fs = require('fs');
const del = require('del');
const json = require('json-update');
var rename = require("gulp-rename");
var cp = require('child_process');
const package = require('./package.json');
const deployment = require('./deployment.json');
We couldn’t find that file to show.
@jkarttunen
jkarttunen / .gitignore
Created August 9, 2020 05:55
.gitignore
# Misc
*.log
npm-debug.*
*.scssc
*.swp
.DS_Store
Thumbs.db
.sass-cache
.env
.cache
@jkarttunen
jkarttunen / .eleventy.js
Created August 9, 2020 05:56
.eleventy.js
module.exports = config => {
return {
dir: {
input: 'src',
output: 'dist'
}
};
};