Instantly share code, notes, and snippets.

💭
boop 😶

ajv andreasvirkus

View GitHub Profile
View curly-bracket.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View deviceIntel.js
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' },
View fizzbuzz.js
for (var i = 1; i <= 100; i++) console.log((i % 3 ? "" : "Fizz") + (i % 5 ? "" : "Buzz") || i)
View fizzbuzz.py
#!/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
View createRange.js
export const createRange = (len, zeroBased = true) =>
new Array(len).fill().map((_, i) => zeroBased ? i : i + 1)
View findParentByClass.js
export const findParentByClass = (el, className) => {
while (el.parentNode) {
el = el.parentNode
if (el.classList && el.classList.contains(className)) return el
}
return null
}
View DateMask.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"
View clipboard.js
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) => {
View fetchy.js
/** 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'
View hash.js
// 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)