Skip to content

Instantly share code, notes, and snippets.

Avatar
🌊

Renārs Vilnis renarsvilnis

🌊
View GitHub Profile
View keybase.md

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:

View pino-http.js
// ...
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 / DelayMount.js
Last active Apr 4, 2017
<DelayMount/> component
View DelayMount.js
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
}
@renarsvilnis
renarsvilnis / imageHelpers.js
Last active May 31, 2017
Helper functions for calculating fit, fill dimensions of an image, rect,.. in JavaScript
View imageHelpers.js
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
View remove-nth-es6.js
/**
* 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)
@renarsvilnis
renarsvilnis / gist:6e8c455663f3601f9f1c
Last active Aug 29, 2015
Tips for web app security
View gist:6e8c455663f3601f9f1c
@renarsvilnis
renarsvilnis / server-setup-guide-warp.md
Last active May 26, 2017
Guide for configuring server for apache, php, ssh etc..
View server-setup-guide-warp.md

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 / php-tricks-n-tips.md
Last active Aug 29, 2015
Some tips or useful info about PHP that i found interesting or useful at the moment of writing.
View php-tricks-n-tips.md
View read-length-of-mp3.php
<?php
ini_set("max_execution_time", "30000");
// how much detail we want. Larger number means less detail
// (basically, how many bytes/frames to skip processing)
// the lower the number means longer processing time
define("DETAIL", 5);
define("DEFAULT_WIDTH", 500);