Skip to content

Instantly share code, notes, and snippets.

View andreasvirkus's full-sized avatar
🙊
made you look

andreas andreasvirkus

🙊
made you look
View GitHub Profile
export const gatherDeviceIntel = () => {
const header = [
navigator.platform,
navigator.userAgent,
navigator.appVersion,
navigator.vendor,
window.opera
]
const dataos = [
{ name: 'Windows Phone', value: 'Windows Phone', version: 'OS' },
for (var i = 1; i <= 100; i++) console.log((i % 3 ? "" : "Fizz") + (i % 5 ? "" : "Buzz") || i)
#!/usr/bin/env python
for x in range(1,101):
s = ""
if x % 3 == 0:
s += "Fizz"
if x % 5 == 0:
s += "Buzz"
if s == "":
s = x
export const createRange = (len, zeroBased = true) =>
new Array(len).fill().map((_, i) => zeroBased ? i : i + 1)
@andreasvirkus
andreasvirkus / findParentByClass.js
Last active December 6, 2018 13:12
A simple loop that traverses the DOM tree until it finds a parent with the specified class.
export const findParentByClass = (el, className) => {
while (el.parentNode) {
el = el.parentNode
if (el.classList && el.classList.contains(className)) return el
}
return null
}
@andreasvirkus
andreasvirkus / DateMask.vue
Created November 23, 2018 10:27
Basic (and with a bit of a buggy UX) date mask input for Vue
<template>
<div
class="q-date-mask"
@keyup.capture="updateValue">
<input
v-if="showDay"
ref="day"
v-model="day"
class="q-date-mask__input q-date-mask__input--day"
type="number"
export const copy = async (text) => {
try {
await navigator.clipboard.writeText(text)
console.log('Text copied:', text)
} catch (err) {
console.error('Failed to copy:', err)
}
}
export const paste = async (selector, readOnly = false) => {
/** Small module to expose get and post methods around fetch for API communication (bearer token in headers, etc.) */
const host = process.env.API_DOMAIN
const prefix = `/api/v1`
export const getData = ({ url, accessToken, paymentId, headers, noJson }) =>
request({ url, accessToken, paymentId, headers, noJson, method: 'GET' })
export const postData = ({ url, accessToken, paymentId, headers, data, method }) => {
method = method || 'POST'
// Generates a small hash (useful for CSRF state params, mocking a token in localStorage for development, etc.)
export const generateHash = str => '_' + Math.random().toString(36).substr(2, 9)
function isPrimeNumber(n) {
for (var i = 2; i < n; i++) { // i will always be less than the parameter so the condition below will never allow parameter to be divisible by itself ex. (7 % 7 = 0) which would return true
if (n % i === 0) return false // when parameter is divisible by i, it's not a prime number so return false
}
return n > 1 // otherwise it's a prime number so return true (it also must be greater than 1, reason for the n > 1 instead of true)
}