Skip to content

Instantly share code, notes, and snippets.

View aryabartar's full-sized avatar
⛱️

Arya Khaligh aryabartar

⛱️
  • Vancouver, Canada
View GitHub Profile
@MadaraUchiha
MadaraUchiha / mysql_comment.markdown
Last active May 9, 2019 23:07
Don't use MySQL functions in PHP - Comment for Stack Overflow
[**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ).

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

@dkarchmer
dkarchmer / django-filter-sample.py
Created May 2, 2016 00:26
How to use django-filter to add a DRF filter using dates and slugs
class SampleFilter(filters.FilterSet):
start_date = django_filters.DateFilter(name="date", lookup_type='gte')
end_date = django_filters.DateFilter(name="date", lookup_type='lte')
# How to filter by a foreign key that uses slug as a lookup
foo = django_filters.ModelMultipleChoiceFilter(
queryset=MyModel.objects.all(),
to_field_name='slug',
conjoined=True,
)
class Meta:
@yxy
yxy / actions.py
Created September 9, 2017 06:44 — forked from mgerring/actions.py
"Export to CSV" action for django admin
import unicodecsv
from django.http import HttpResponse
def export_as_csv_action(description="Export selected objects as CSV file",
fields=None, exclude=None, header=True):
"""
This function returns an export csv action
'fields' and 'exclude' work like in django ModelForm
'header' is whether or not to output the column names as the first row
"""
@mgerring
mgerring / actions.py
Created September 5, 2012 22:04
"Export to CSV" action for django admin
import unicodecsv
from django.http import HttpResponse
def export_as_csv_action(description="Export selected objects as CSV file",
fields=None, exclude=None, header=True):
"""
This function returns an export csv action
'fields' and 'exclude' work like in django ModelForm
'header' is whether or not to output the column names as the first row
"""
@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@jolestar
jolestar / ipsec-shadowsocks.sh
Last active November 14, 2021 06:53
Run ipsec vpn and shadowsocks by docker, for ubuntu 16
PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
apt-get update
apt-get install apt-transport-https ca-certificates
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install -y docker-engine
service docker start
@jeremyjbowers
jeremyjbowers / actions.py
Created November 24, 2015 21:47
Export to CSV for Django admin
import csv
from django.http import HttpResponse
def export_as_csv_action(description="Export selected objects as CSV file", fields=None, exclude=None, header=True):
"""
This function returns an export csv action
'fields' and 'exclude' work like in django ModelForm
'header' is whether or not to output the column names as the first row
"""
def export_as_csv(modeladmin, request, queryset):
@tyt2y3
tyt2y3 / chatroom.py
Created July 11, 2015 10:00
Simple chatroom in Python, upon BaseHTTPServer and long polling
'''
Simple chatroom
Reference
https://docs.python.org/2/library/threading.html
http://blog.oddbit.com/2013/11/23/long-polling-with-ja/
http://zulko.github.io/blog/2013/09/19/a-basic-example-of-threads-synchronization-in-python/
http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/
'''
@trongthanh
trongthanh / mojave.xml
Last active January 26, 2023 19:04
macOS Mojave dynamic background re-implement as GTK+ background slideshow. Background images are changed to reflect the time of the day.
<!-- Instructions:
- Download and unzip Mojave dynamic background here: https://files.rb.gd/mojave_dynamic.zip
- Rename the extracted folder as "mojave-background" (Excuse the trouble but I renamed it on my machine and already use that path in the XML file)
- Save this xml file next to the Mojave background files
- Fix the path to the background images below (better using absolute path)
- Lastly, either:
+ GNOME: Use gnome-tweaks tool to select this XML as wallpaper (as default wallpaper settings won't let you choose wallpaper from custom path)
+ MATE: Go to background setting (in Appearance) > Choose +Add... > make sure **All files** filter is selected at the bottom right > Then choose mojave.xml
-->
<background>
@gengue
gengue / serializers.py
Last active February 2, 2023 03:50
Django Rest Framework user endpoint with change password
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from rest_framework import serializers
from .models import User
class UserSerializer(serializers.ModelSerializer):
"""
User accounts serializer