Skip to content

Instantly share code, notes, and snippets.

@eXtrem0us
eXtrem0us / nginx.conf
Last active April 15, 2024 13:47
Nginx Image Filter with Caching for Upstream
########################################################################################################
# This config enables us to:
# - Resize
# - Rotate
# ...the resident images on an upstream server, with Nginx Server in our hand, On the fly!
# - Just by using arbitrary Query Parameters
# ...and
# - Cache the transformed image by address.
#
# Well, I got the Idea from https://stumbles.id.au/nginx-dynamic-image-resizing-with-caching.html
@hr-sadooghi
hr-sadooghi / fa2EnDigit-en2FaDigit.sql
Created February 27, 2017 08:09
english digit to persian digit and reverse
DROP FUNCTION IF EXISTS fa2EnDigit;
DELIMITER $$
CREATE FUNCTION fa2EnDigit(str TEXT) RETURNS TEXT
BEGIN
DECLARE t TEXT;
SET t = str;
SET t = REPLACE(t, '۱', '1');
SET t = REPLACE(t, '۲', '2');
SET t = REPLACE(t, '۳', '3');
SET t = REPLACE(t, '۴', '4');
@tzmartin
tzmartin / m3u8-to-mp4.md
Last active May 8, 2024 18:52
m3u8 stream to mp4 using ffmpeg

1. Copy m3u8 link

Alt text

2. Run command

echo "Enter m3u8 link:";read link;echo "Enter output filename:";read filename;ffmpeg -i "$link" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 $filename.mp4
@amirasaran
amirasaran / Java Script replace all in string (str_replace)
Created September 27, 2016 06:09
Java Script replace all in string (str_replace)
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
/**
* Example
*/
@mhipo1364
mhipo1364 / merge_migration.md
Created August 3, 2016 21:54
Re-Generate(Merge) Migration Files In Django

Re-Generate Migration

To merge exist migration files into one file:

  • Remove django_migration records table (manually)
  • Remove all migration files
  • run python manage.py migrate --fake command
  • run python manage.py makemigrations command
  • run python manage.py migrate --fake-initial command
  • run python manage.py migrate contenttypes command
import telegram
def main():
bot = telegram.Bot(token="113351444:AAGmDDOkLqvzCESShVAfzwBgLiT1R9UvUK0")
lui = bot.getUpdates()[-1].update_id
print lui
while True:
for updates in bot.getUpdates(offset=lui,timeout=10):
text = updates.message.text
chat_id = updates.message.chat.id
update_id = updates.update_id
@yprez
yprez / fields.py
Last active February 19, 2023 12:08
Django rest framework - Base64 image field
import base64
from django.core.files.base import ContentFile
from rest_framework import serializers
class Base64ImageField(serializers.ImageField):
def from_native(self, data):
if isinstance(data, basestring) and data.startswith('data:image'):
# base64 encoded image - decode
@philippeowagner
philippeowagner / gist:6530635
Last active November 25, 2020 13:02
Having troubles with 'latin1_swedish_ci' on your MySQL Databases? Specially `OperationalError (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='")`? No problem, fix it using Django's shell.This solution is based on this http://stackoverflow.com/questions/1073295/django-character-set-w…
from django.db import connection
from django.conf import settings
cursor = connection.cursor()
cursor.execute('SHOW TABLES')
results=[]
for row in cursor.fetchall():
results.append(row)
for row in results:
cursor.execute('ALTER TABLE %s CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' % (row[0]))
@jaivikram
jaivikram / getVideoDetails.py
Last active April 18, 2020 13:02
Python gist to obtain video details like duration, resolution, bitrate, video codec and audio codec, frequency using 'ffmpeg'
#! /usr/bin/env python
import os
import sys
import re
import tempfile
def getVideoDetails(filepath):
tmpf = tempfile.NamedTemporaryFile()
os.system("ffmpeg -i \"%s\" 2> %s" % (filepath, tmpf.name))
lines = tmpf.readlines()
@eparreno
eparreno / gist:1845561
Created February 16, 2012 15:17
Install libmagic on Mac OS X via homebrew
$ brew install libmagic
$ brew link libmagic (if the link is already created is going to fail, don't worry about that)
$ env ARCHFLAGS="-arch x86_64" gem install ruby-filemagic -- --with-magic-include=/usr/local/include --with-magic-lib=/usr/local/lib/