Skip to content

Instantly share code, notes, and snippets.

View mesuutt's full-sized avatar

Mesut Taşçı mesuutt

View GitHub Profile
@mesuutt
mesuutt / postgresql.md
Last active November 9, 2021 19:09
Kullanisli Postgresql Sorgulari
@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 / city.json
Last active January 21, 2018 01:20
Django projeleri için il-ilçe fixtureları ve modeli (İl id'leri plaka kodlarıdır)
[
{
"model": "other.city",
"pk": 1,
"fields": {
"name": "ADANA"
}
},
{
"model": "other.city",
DELETE = "delete"
UPDATE = "update"
SELECT = "select"
INSERT = "insert"
QUOTE = "'"
def format_parameter(parameter, value):
return "%s = %s" % (parameter, determine_quote(value))
@mesuutt
mesuutt / form_widgets.py
Last active August 23, 2017 13:02
Custom form widget for add additional attributes to option tags of select on Django forms.
from django import forms
from django.utils.encoding import force_text
from django.utils.html import format_html
from django.utils.safestring import mark_safe
class SelectOptionsWithAttrs(forms.widgets.Select):
def render_options(self, selected_choices):
# Normalize to strings.
selected_choices = set(force_text(v) for v in selected_choices)
@mesuutt
mesuutt / rates.py
Last active March 7, 2018 09:37
Show BTC,ETH and LTC exchange rates without leaving commandline.
import re
import sys
import getopt
from datetime import datetime, timedelta
from decimal import Decimal
import requests
GREEN = '\033[0;32m'
RED = '\033[0;31m'
MAGENTA = '\033[0;35m'
@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 / 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>
@mesuutt
mesuutt / convert-timestamp.js
Created November 10, 2016 02:05
Convert a timestamp to user's local time via JavaScript
function convertToLocalTimestamp(timestamp) {
var offset = new Date().getTimezoneOffset();
return timestamp + (60 * offset * 1000);
}
// convertToLocalTimestamp(1479168000000);
@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