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
@andreasvirkus
andreasvirkus / nullPad.js
Created May 7, 2018 06:34
Pad a number with leading zeros
export default (value) => {
return ('00' + value).slice(String(value).length);
}
#!/bin/bash
# Print string in an X
for ((i=${#1}-1; i>=0; i--)); do
printf "%$((${#1}-i+1))s\\r%b%s\\n" \
"${1:$((max-i-1)):1}" "\\033[$((i+1))C" "${1:$i:1}"
done
/*
A date formatter filter for SSGs/templating languages
*/
module.exports = (date) => {
const month = [
"January",
"February",
"March",
"April",
"May",
module.exports = {
100: 'Continue',
101: 'Switching Protocols',
200: 'Success',
201: 'Created',
202: 'Accepted',
203: 'Non-Authoritative Information',
204: 'No Content',
205: 'Reset Content',
206: 'Partial Content',
@andreasvirkus
andreasvirkus / featherRequest.js
Created April 29, 2018 08:24
lightweight Node Promise-based request module
const http = require('http')
const https = require('https')
const url = require('url')
module.exports = {
urlCheck,
request
}
function urlCheck(url) {
/* Remember to add styles for the .caps class */
.caps {
font-size: 1.4em;
}
// The polling function
function poll(fn, condition) {
const endTime = Number(new Date()) + timeout
const checkCondition = (resolve, reject) => fn()
.then(response => {
if (condition(response)) {
resolve(response)
} else if (Number(new Date()) < endTime) {
// Condition isn't met but the timeout hasn't elapsed, go again
setTimeout(checkCondition, interval, resolve, reject)
function *pollForWeatherInfo(){
while (true) {
yield fetch('/api/currentWeather', {
method: 'get'
}).then(res => res.json())
}
}
function runPolling(generator){
if (!generator) {
@andreasvirkus
andreasvirkus / DropdownLink.vue
Last active April 21, 2018 04:41
Dropdown in Vue
import nprogress from 'nprogress'
export default {
// ...
// configure progress bar
nprogress.configure({ showSpinner: false })
this.$router.beforeEach((to, from, next) => {
if (to.path !== from.path && !Vue.component(pathToComponentName(to.path))) {