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
function fetchStream(url) {
const req = new Request(url)
return fetch(req).then(rs => {
const reader = rs.body.getReader()
return reader.read().then(({ done, value }) => {
const decoder = new TextDecoder('utf-8')
return decoder.decode(value)
}).catch(err => console.log(`Could not fetch from ${url}!`, err))
const date = new Date()
const day = date.getDate()
const month = date.getMonth() + 1
const year = date.getFullYear()
const time = `${month}/${day}/${year}`
@andreasvirkus
andreasvirkus / trunc.js
Created September 29, 2017 07:40
Truncate strings
String.prototype.trunc = String.prototype.trunc || function(n) {
return (this.length > n) ? this.substr(0, n-1) + '…' : this;
};
import wait from './wait';
//...
save(formData) {
//...
upload(formData)
.then(wait(1500)) // DEV ONLY: wait for 1.5s
.then(x => {
this.uploadedFiles = [].concat(x);
@andreasvirkus
andreasvirkus / easings.js
Last active September 22, 2017 14:16
A snippet to smoothly scroll to elements
export const easings = {
linear(t) {
return t;
},
easeInQuad(t) {
return t * t;
},
easeOutQuad(t) {
return t * (2 - t);
},
export const serve = (path, cache) => express.static(resolve(path), {
maxAge: cache && isProd ? 60 * 60 * 24 * 30 : 0
})
@andreasvirkus
andreasvirkus / resize.js
Last active September 14, 2017 12:26 — forked from arturparkhisenko/resize.js
resize and throttle with rAF
//https://developer.mozilla.org/en-US/docs/Web/Events/resize
(function() {
var throttle = function(type, name, obj_) {
var obj = obj_ || window;
var running = false;
var func = function() {
if (running) {
return;
}
.brdr-envelope {
background-image: url(envelope-border.png);
background-position: 0 100%;
background-repeat: repeat-x;
background-size: 40px 3px;
}
@andreasvirkus
andreasvirkus / .env
Created September 12, 2017 11:43
Running npm scripts with env variables; the comfy way.
NODE_ENV=development
@andreasvirkus
andreasvirkus / pullGitBoilerplate.sh
Created August 19, 2017 07:56
Sometimes you wish to pull in a boilerplate for your gh-pages branch.
export REPO_NAME=repo
export RELEASE=release-or-branch
curl -L https://github.com/user-or-org/$REPO_NAME/archive/$RELEASE.tar.gz | tar xz \
&& mv $REPO_NAME-$RELEASE/* ./