Skip to content

Instantly share code, notes, and snippets.

View renarsvilnis's full-sized avatar
🌊

Renārs Vilnis renarsvilnis

🌊
View GitHub Profile
alert('Hello world!');
@renarsvilnis
renarsvilnis / server-setup-guide-warp.md
Last active December 11, 2022 21:48
Guide for configuring server for apache, php, ssh etc..

DEV SERVER SETUP


A reference for setting up Linux/Ubuntu server for LAMP, Node.js laboratory.

May be helpful for others, hence this git. If it contains errors, please push them.

This assumes

@renarsvilnis
renarsvilnis / vimeoUrlParser.js
Last active May 30, 2022 13:56
Javascript helper function to validate if url is a valid Vimeo video url.
function parseVimeoUrl(url) {
const regExp = /(?:https?:\/\/(?:www\.)?)?vimeo.com\/(?:channels\/|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/;
const match = url.match(regExp);
return match ? match[3] : false;
}

Keybase proof

I hereby claim:

  • I am renarsvilnis on github.
  • I am renarsvilnis (https://keybase.io/renarsvilnis) on keybase.
  • I have a public key ASCqW6nmRyxAuawicthyZFzwvp-FVybO76yYRTzLcdfr7go

To claim this, I am signing this object:

// ...
function loggingMiddleware (req, res, next) {
const id = genReqId(req)
req.log = res.log = logger.child({reqId: id})
req.log[useLevel]({req}, 'Recieved request')
res[startTime] = res[startTime] || Date.now()
if (!req.res) { req.res = res }
res.on('finish', onResFinished)
@renarsvilnis
renarsvilnis / youtubeUrlParser.js
Last active December 13, 2017 08:20
Javascript function to validate if url is a valid vimeo video url.
function parseYoutubeUrl(url) {
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/,
match = url.match(regExp);
return match && match[7].length == 11 ? match[7] : false;
}
@renarsvilnis
renarsvilnis / imageHelpers.js
Last active May 31, 2017 09:05
Helper functions for calculating fit, fill dimensions of an image, rect,.. in JavaScript
export function calcFitDimensions (target, boundries, upscale = false) {
if (!target.width || !target.height || !boundries.width || !boundries.height) {
return calcCenterPosition(target, boundries);
}
let imgRatio = target.width / target.height;
let newWidth;
let newHeight;
// if image is horizontal
@renarsvilnis
renarsvilnis / DelayMount.js
Last active April 4, 2017 20:10
<DelayMount/> component
import {PureComponent, PropTypes} from 'react';
export default class DelayMount extends PureComponent {
static propTypes = {
render: PropTypes.bool.isRequired,
children: PropTypes.any,
transitionEnterDelay: PropTypes.number.isRequired,
transitionLeaveTimeout: PropTypes.number.isRequired
}
/**
* ES6 way of removing nth array element in an immutable way
* @param [Array] arr
* @param [number] i
* @return [Array]
*/
function removeNthEl (arr, i) {
return [
...arr.slice(0, i),
...arr.slice(i + 1)