Skip to content

Instantly share code, notes, and snippets.

View zarcode's full-sized avatar

Zarko Dencic zarcode

View GitHub Profile
@zarcode
zarcode / react-native.js
Created April 20, 2018 20:24 — forked from lelandrichardson/react-native.js
React Native flow types
declare var __DEV__: boolean;
declare module 'react-native' {
declare type Color = string | number;
declare type Transform =
{ perspective: number } |
{ scale: number } |
{ scaleX: number } |
@zarcode
zarcode / async.js
Last active November 9, 2019 07:53
fetch with status code handling
async function asyncCall() {
let response = await fetch("https://httpstat.us/500")
if (response.ok) return await response.text()
throw new Error(response)
}
async function callFetch() {
try {
let const = await asyncCall()
console.log(text)
@zarcode
zarcode / index.js
Created April 7, 2018 12:50
chaining CSS transitions with Promise
function transitionEndPromise(element) {
return new Promise(resolve => {
element.addEventListener('transitionend', function f() {
element.removeEventListener('transitionend', f);
resolve();
});
});
}
function animateOut(oldView) {
@zarcode
zarcode / knights_tour.js
Last active April 4, 2018 08:30
Warnsdorff’s algorithm for Knight’s tour problem in JavaScript/ES6 https://www.geeksforgeeks.org/warnsdorffs-algorithm-knights-tour-problem/
// ES6 program to for Knight's tour problem using
// Warnsdorff's algorithm
const N = 8;
let gx;
let gy;
const a = [];
function print(a) {
for (let i = 0; i < N; i += 1) {
let s = '';
@zarcode
zarcode / array-utility.js
Last active December 19, 2017 10:18
Array utility functions
/**
* Flattens the multidimensional array
* @param {Array} array - some multidimensional array
* @returns {Array} flattened array
*/
function flatten(array) {
return array.reduce(function(acc, curr) {
var items = Array.isArray(curr)? flatten(curr) : [curr];
return acc.concat(items);
}, []);