Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta name="description" content="following https://medium.com/@natelapinski/learning-observables-part-1-arrays-14480816eb61">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@Zurc
Zurc / api.service.ts
Created August 29, 2019 05:57
angular - centralized api connections
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { environment } from '../../environments/environment';
export interface HttpOptions {
headers?: { [key: string]: string };
query?: { [key: string]: string };
}
@Zurc
Zurc / Observables
Last active May 1, 2019 11:35
Observables
// ref: https://x-team.com/blog/rxjs-observables/
// imagine that we have a button and whenever the button is clicked, a quasi-random string is generated and displayed
const output = document.querySelector('output');
const button = document.querySelector('button');
Rx.Observable
.fromEvent(button, 'click')
.subscribe(() => {
output.textContent = Math.random().toString(36).slice(2);
@Zurc
Zurc / JS string methods
Last active May 1, 2019 11:21
JS string methods
// ref; https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Useful_string_methods
var string = 'This is my string';
// Find length
string.length;
// Retrieve a specific character
string[0];
const exampleArray = [[1,2,[3]],4];
const flatten = []
function flatNestedIntegersArray(nestedArray) {
nestedArray.forEach(element => {
if( Number.isInteger(element) ) {
flatten.push(element)
} else {
flatNestedIntegersArray(element)
}
@Zurc
Zurc / QueryParams.js
Created November 29, 2017 14:32 — forked from andrewjmead/QueryParams.js
Get Query Params By Name
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
@Zurc
Zurc / Battery-status
Created November 29, 2017 10:16
Battety status API
navigator.getBattery().then((battery) => {
console.log(`${battery.level * 100}%`);
battery.addEventListener('levelchange', () => {
console.log(`${this.level * 100}%`);
});
});
@Zurc
Zurc / Geolocation.getCurrentPosition
Created November 29, 2017 09:49
Geolocation Get Current Position
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
const entityTypes = [
{ category: 'Root', initial: 'oe', icon: '', class: 'card-root' },
{ category: 'Client', initial: 'c', icon: 'fa fa-diamond', class: 'card-client' },
{ category: 'Site', initial: 's', icon: 'fa fa-map-marker', class: 'card-site' },
{ category: 'Device', initial: 'd', icon: 'fa fa-cubes', class: 'card-device' },
{ category: 'Load', initial: 'l', icon: 'fa fa-cube', class: 'card-load' },
{ category: 'Meter', initial: 'm', icon: 'fa fa-tachometer', class: 'card-meter' },