Skip to content

Instantly share code, notes, and snippets.

View mesuutt's full-sized avatar

Mesut Taşçı mesuutt

View GitHub Profile
@mesuutt
mesuutt / rename-kubeconfigs.sh
Last active November 4, 2022 11:18
Rename kubeconfig files with cluster's name.
#!/bin/bash
# exit on error
set -e
CONF_DIR=~/.kube/config.d
require() {
if ! hash "$1" &>/dev/null; then
@mesuutt
mesuutt / kctx.sh
Last active June 2, 2022 11:41
rename kubeconfig files with cluster name
#!/bin/bash
# alias kctx="source ~/.bin/kctx.sh"
CONF_DIR=~/.kube/config.d
file=$(ls -1 $CONF_DIR | fzf)
echo "$file"
if [[ ! "$file" == "null" ]]; then

Traits

Trait bound:

trait bound fonksiyon tanimi(static dispatch):

fn foo<T: MyTrait>(f: &T) {}

Static type dispach yapar. foo(inek), foo(koyun) gibi cagirdigimizda compile time'da iki ayri fn generate edilir.

// formatter adds default fields to each log entry. https://github.com/sirupsen/logrus/pull/653#issuecomment-454467900
type formatter struct {
Fields logrus.Fields
Lf logrus.Formatter
}
// Format satisfies the logrus.Formatter interface.
func (f *formatter) Format(e *logrus.Entry) ([]byte, error) {
for k, v := range f.Fields {
e.Data[k] = v
@mesuutt
mesuutt / request_logging.rs
Last active February 14, 2021 21:57
actix-web(3) logging middleware with slog (2.7)
use actix_service::{Service, Transform};
use actix_web::{dev::ServiceRequest, dev::ServiceResponse, Error};
use futures::future::{ok, Ready};
use futures::{Future};
use slog::info;
use futures::task::Poll;
use std::task::Context;
use std::pin::Pin;
@mesuutt
mesuutt / access_postgresql_with_docker.md
Created November 14, 2020 23:40 — forked from MauricioMoraes/access_postgresql_with_docker.md
Allow Docker Container Access to Host's Postgres Database on linux (ubuntu)

You have to do 2 things in order to allow your container to access your host's postgresql database

  1. Make your postgresql listen to an external ip address
  2. Let this client ip (your docker container) access your postgresql database with a given user

Obs: By "Host" here I mean "the server where docker is running on".

Make your postgresql listen to an external ip address

Find your postgresql.conf (in case you don't know where it is)

$ sudo find / -type f -name postgresql.conf

import 'package:flutter/material.dart';
void main() async {
runApp(new TestApp());
}
class TestApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@mesuutt
mesuutt / nested_scroll_view.dart
Created February 13, 2019 13:43 — forked from collinjackson/nested_scroll_view.dart
nestedscrollview example
// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
runApp(new TestApp());
}
@mesuutt
mesuutt / format-money.dart
Last active February 11, 2019 14:39
Format money as Turkish money format in dart language
String formatMoney(dynamic text) {
if (text is num){
text = text.toStringAsFixed(2);
}
return text
.toString()
.replaceAllMapped(RegExp(r"(\d)(?=(\d{3})+\.)"), (m) => "${m.group(1)}.")
.replaceAllMapped(RegExp(r"\.(\d+)$"), (m) => ",${m.group(1)}");
}
@mesuutt
mesuutt / views.py
Last active October 25, 2018 11:49
Django save file to storage & Read from storage without model
from django.core.files.storage import default_storage
# Saving POST'ed file to storage
file = request.FILES['myfile']
filename = default_storage.save(file.name, file)
# Reading file from storage
file = default_storage.open(filename)