Skip to content

Instantly share code, notes, and snippets.

View mesuutt's full-sized avatar

Mesut Taşçı mesuutt

View GitHub Profile
@mesuutt
mesuutt / format-money-try.js
Last active April 23, 2024 17:57
Format money as Turkish money format.
function formatMoney(n) {
return parseFloat(n).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1.').replace(/\.(\d+)$/,',$1');
}
formatMoney(1234567) // 1.234.567,00
formatMoney(1234567.99) // 1.234.567,99
@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

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.

@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
@mesuutt
mesuutt / ajax-setup.js
Last active May 2, 2022 16:32
Django handling expired session (for ajax request)
$.ajaxSetup({
complete: function(xhr, status) {
if(xhr.status == 278) {
if (xhr.responseJSON) {
var data = xhr.responseJSON;
if (!data.success && data.error_message) {
alert(data.error_message);
}
}
@mesuutt
mesuutt / postgresql.md
Last active November 9, 2021 19:09
Kullanisli Postgresql Sorgulari
@mesuutt
mesuutt / .bashrc
Last active October 26, 2021 09:47
Check active window every second and run script when window class changed
# ....
# Run script if not running.
if ! pidof -x "catch_window_change.sh" > /dev/null; then
(~/bin/catch_window_change.sh > /dev/null 2>&1 &)
fi
@mesuutt
mesuutt / chart.html
Last active March 23, 2021 02:08
Chart.js - Doughnut chart with custom legend http://codepen.io/mesuutt/pen/LbyPvr
<div class="canvas-con">
<div class="canvas-con-inner">
<canvas id="mychart" height="250px"></canvas>
</div>
<div id="my-legend-con" class="legend-con"></div>
</div>
// 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;