Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
🦀

Mesut Taşçı mesuutt

💭
🦀
View GitHub Profile
View logrus.go
// 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 Feb 14, 2021
actix-web(3) logging middleware with slog (2.7)
View request_logging.rs
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 Nov 14, 2020 — forked from MauricioMoraes/access_postgresql_with_docker.md
Allow Docker Container Access to Host's Postgres Database on linux (ubuntu)
View access_postgresql_with_docker.md

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

View nested_scroll_demo.dart
import 'package:flutter/material.dart';
void main() async {
runApp(new TestApp());
}
class TestApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
View nested_scroll_view.dart
// 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 Feb 11, 2019
Format money as Turkish money format in dart language
View format-money.dart
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 Oct 25, 2018
Django save file to storage & Read from storage without model
View views.py
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)
@mesuutt
mesuutt / postgresql.md
Last active Feb 29, 2020
Kullanisli Postgresql Sorgulari
View postgresql.md
@mesuutt
mesuutt / ajax-setup.js
Last active Feb 25, 2018
Django handling expired session (for ajax request)
View ajax-setup.js
$.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 / city.json
Last active Jan 21, 2018
Django projeleri için il-ilçe fixtureları ve modeli (İl id'leri plaka kodlarıdır)
View city.json
[
{
"model": "other.city",
"pk": 1,
"fields": {
"name": "ADANA"
}
},
{
"model": "other.city",