Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<?php
namespace Tests\Feature;
use App\User;
use Laravel\Cashier\SubscriptionBuilder;
use Tests\TestCase;
use function route;
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class PlansController extends Controller
{
@karakanb
karakanb / docker-compose.yml
Last active November 2, 2020 00:04
simple pi-hole docker-compose setup
version: "3.8"
services:
pihole:
container_name: pihole
image: pihole/pihole:v5.1.2
restart: always
environment:
TZ: 'Europe/Berlin' # Put your own timezone here.
@karakanb
karakanb / naive.go
Last active December 15, 2020 17:56
func parseWithDateTime(inputString string) int {
t, _ := time.Parse("3PM", inputString)
number, _ := strconv.Atoi(t.Format("15"))
return number
}
package main
import (
"testing"
)
func BenchmarkParseWithDateTime(b *testing.B) {
for n := 0; n < b.N; n++ {
parseWithDateTime("7PM")
}
func parseWithReplaceAll(inputString string) int {
isAm := strings.HasSuffix(inputString, "AM")
if isAm {
inputString = strings.ReplaceAll(inputString, "AM", "")
} else {
inputString = strings.ReplaceAll(inputString, "PM", "")
}
number, _ := strconv.Atoi(inputString)
func BenchmarkParseWithReplaceAll(b *testing.B) {
for n := 0; n < b.N; n++ {
parseWithReplaceAll("7PM")
}
}
func parseWithReplaceAllTrimSuffix(inputString string) int {
isAm := strings.HasSuffix(inputString, "AM")
if isAm {
inputString = strings.TrimSuffix(inputString, "AM")
} else {
inputString = strings.TrimSuffix(inputString, "PM")
}
number, _ := strconv.Atoi(inputString)
func BenchmarkParseWithReplaceAllTrimSuffix(b *testing.B) {
for n := 0; n < b.N; n++ {
parseWithReplaceAllTrimSuffix("7PM")
}
}