Skip to content

Instantly share code, notes, and snippets.

View Elbone's full-sized avatar

Niels Oeltjen Elbone

View GitHub Profile
@Elbone
Elbone / truncate.js
Last active December 8, 2020 06:03
Truncate the middle of a string
const truncate = function(fullStr, strLen, separator) {
if (fullStr.length <= strLen) return fullStr;
separator = separator || '…';
const sepLen = separator.length;
const charsToShow = strLen - sepLen;
const frontChars = Math.ceil(charsToShow/2);
const backChars = Math.floor(charsToShow/2);
@Elbone
Elbone / useful.js
Created August 14, 2020 02:08
Useful js
// LOOP ARRAY KEYS and INDEXES
let myArray = ['fruit', 'fish', 'seahorses', 'mudslides'];
for (let [index, value] of myArray.entries()) {
console.log(index, value);
}
/*
0 "fruit"
1 "fish"
@Elbone
Elbone / HTML Character Codes
Created January 8, 2019 03:51 — forked from jonathansousa/HTML Character Codes
HTML: Character Codes
Name Character Entity
Copyright © &copy;
Registered ® &reg;
Trademark ™ &trade;
Curly Open Double Quote “ &ldquo;
Curly Closed Double Quote ” &rdquo;
Curly Open Single Quote ‘ &lsquo;
Curly Closed Single Quote ’ &rsquo;
Big Bullet/Dot • &bull;
@Elbone
Elbone / ux-tools.md
Last active May 10, 2018 00:09
UX Tools

Flow charts (Also coming soon is Wireframes and Stickies)

@Elbone
Elbone / tools.md
Last active May 10, 2018 03:15
List of UI prototyping and design tools
@Elbone
Elbone / collate-pdf
Created October 11, 2017 23:23
Collate PDFs on the command line in OSX
cd /path/to/directory/
/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py --output collated.pdf *.pdf
@Elbone
Elbone / loops.js
Created October 8, 2017 23:16
Loops in Javascript
// My preferred method
let obj = {"one" : 1, "two" : 2, "three": 3 }
for (let k of Object.keys(obj)) {
console.log(k, obj[k])
}
/*
Timer
- utilises animation frames (with a fallback to setTimeout when using the polyfill, below)
- returns remaining (or running) time
- pass a callback [fn], with an optional duration [ms] and autotart [bool], to the constructor or 'init' method
eg. new Timer(foo, 1000) *or* (new Timer()).init(foo, 0, true)
- for uniform x-browser support combine with the requestAnimationFrame polyfill from Erik Möller, et. al.
[https://github.com/darius/requestAnimationFrame]
*/
@Elbone
Elbone / get_url_parts.js
Last active July 12, 2017 06:26
Get component parts of a url in js
// From here:
// https://stackoverflow.com/questions/1420881/how-to-extract-base-url-from-a-string-in-javascript/26708573#26708573
const parseUrl = (string, prop) => {
const a = document.createElement('a');
a.setAttribute('href', string);
const {host, hostname, pathname, port, protocol, search, hash} = a;
const origin = `${protocol}//${hostname}${port.length ? `:${port}`:''}`;
return prop ? eval(prop) : {origin, host, hostname, pathname, port, protocol, search, hash}
}
@Elbone
Elbone / Tel_Number_Formatting.md
Last active May 11, 2017 02:23
How phone numbers are formatted in Australia

Interstate call

eg. 02 6555 1234

0         - trunk prefix
2         - Area code for New South Wales
6555      - STD code for a specific telephone exchange
1234      - Telephone Exchange specific extension.