Skip to content

Instantly share code, notes, and snippets.

@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 / 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]);
}
}
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 / 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];
@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 / 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 };
}
<!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">
<!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 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>
@Zurc
Zurc / _cssTable.sass
Created January 21, 2020 19:31 — forked from if540/_cssTable.sass
css table (Bem style)
/* cssTable */
.c-cssTable
display: table
+has(thead)
display: table-header-group
+has(tbody)
display: table-row-group