Skip to content

Instantly share code, notes, and snippets.

Avatar

Mesut Taşçı mesuutt

View GitHub Profile
@mesuutt
mesuutt / ajax-setup.js
Last active May 2, 2022
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",
View gist:757e1f1e892f0eff63e6e5c50e2541d7
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 Aug 23, 2017
Custom form widget for add additional attributes to option tags of select on Django forms.
View form_widgets.py
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 Mar 7, 2018
Show BTC,ETH and LTC exchange rates without leaving commandline.
View rates.py
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 Feb 14, 2022
Format money as Turkish money format.
View format-money-try.js
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 Mar 23, 2021
Chart.js - Doughnut chart with custom legend http://codepen.io/mesuutt/pen/LbyPvr
View chart.html
<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 Nov 10, 2016
Convert a timestamp to user's local time via JavaScript
View convert-timestamp.js
function convertToLocalTimestamp(timestamp) {
var offset = new Date().getTimezoneOffset();
return timestamp + (60 * offset * 1000);
}
// convertToLocalTimestamp(1479168000000);
@mesuutt
mesuutt / .bashrc
Last active Oct 26, 2021
Check active window every second and run script when window class changed
View .bashrc
# ....
# 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 / i3block-take-a-break.sh
Created Oct 13, 2016
Break reminder for i3blocks.
View i3block-take-a-break.sh
#!/bin/bash
#[remind_break]
#command=~/.i3/i3blocks/take-a-break.sh
#interval=10
# Minutes
work_time=20
break_time=5