Skip to content

Instantly share code, notes, and snippets.

function round(value, precision) {
var multiplier = Math.pow(10, precision || 0);
var num = (Math.round(value * multiplier) / multiplier).toString();
return num.indexOf('.') ? num : num + '.0';
}
function shortNumberFormatter(number) {
if (number < 900) {
return number;
}
@motia
motia / remove-merged-branches.sh
Created February 12, 2020 13:08
Remove branches merged into the current branch
function remove-merged-branches () {
currentBranch=$(git rev-parse --abbrev-ref HEAD)
read -p "Delete branches merges into $currentBranch y/N? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
git branch --merged | grep -v $currentBranch | while read i; do git branch -d $i; done;
echo "Branches removed successfully"
else
@motia
motia / error_handler.dart
Created October 28, 2019 15:03
Flutter Sentry Setup
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:sentry/sentry.dart';
class ErrorHandler {
static ErrorHandler _instance;
SentryClient _sentry;
final bool isInDebugMode;
@motia
motia / auth.js
Created April 18, 2019 11:17 — forked from zolotyx/auth.js
Nuxt Auth Redirect Fix
export const isSameURL = (a, b) => a.split('?')[0] === b.split('?')[0]
export const isRelativeURL = u =>
u && u.length && /^\/[a-zA-Z0-9@\-%_~][/a-zA-Z0-9@\-%_~]*[?]?([^#]*)#?([^#]*)$/.test(u)
export default function ({ app }) {
const redirect = function (name, noRouter = false) {
if (!this.options.redirect) {
return
}
@motia
motia / auth-middleware.js
Last active August 19, 2017 22:15
Nuxt JWT
export default async function ({ store, route, redirect }) {
store.dispatch('auth/loadToken')
const hasToken = Boolean(store.state.auth.token)
const isLoggedIn = store.state.auth.loggedIn
// if have a token
if (hasToken) {
if (route.path === '/login') {
redirect('/')
return
@motia
motia / ArtisanCommandTrait.php
Last active December 26, 2016 11:26
a trait for calling child artisan commands, it allows passing arguments such as quiet and no-interaction to child artisan command.
<?php
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
trait ArtisanCommandTrait{
public function executeArtisanCommand($command, $options){
$stmt = 'php artisan '. $command . ' ' . $this->prepareOptions($options);
$process = new Process($stmt);