Skip to content

Instantly share code, notes, and snippets.

View svfat's full-sized avatar

Stan Fateev svfat

View GitHub Profile
@svfat
svfat / gist:1d9e98cf0b789196ec1d
Created September 22, 2014 10:26
Nice white border around text in CSS
.text {
text-shadow: 2px 0 0 #fff, -2px 0 0 #fff, 0 2px 0 #fff, 0 -2px 0 #fff, 1px 1px #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
}
/* https://stackoverflow.com/questions/13426875/text-border-using-css-border-around-text */
@svfat
svfat / urls.py
Created September 22, 2014 11:59
Django robots.txt "disallow all bots"
from django.http import HttpResponse
urlpatterns = patterns('',
...
(r'^robots\.txt$', lambda r: HttpResponse("User-agent: *\nDisallow: /", mimetype="text/plain"))
)
@svfat
svfat / gist:2300c7420776289ecad5
Created May 22, 2015 19:47
Django - Get queryset from filtered objects with parameters from request
from django.views.generic import ListView
from sampleapp.models import Sample
class CustomListView(ListView):
def get_queryset(self):
query_dict = self.request.GET
return Sample.objects.filter(**query_dict.dict())
@svfat
svfat / gist:2cf263613f4d401671d7
Created May 28, 2015 07:58
Config abstraction
# coding: utf-8
"""
Abstraction above configuration data:
Used to load any data in dictionary format into object,
as class properties.
Example:
data = {'threads':30, 'name':'Stan', 'something':[1, 'dd', 13]}
cfg = config.AbstractConfig(data)
print cfg.threads
@svfat
svfat / gist:8baeeb5b589dd241c206
Created June 16, 2015 09:34
django admin register shortcut
from django.contrib import admin
from .models import Post
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
pass
@svfat
svfat / app.js
Created June 16, 2015 13:24
remove hash (sharp) signs from angular ui router URLs
app.config(["$locationProvider", function($locationProvider) {
$locationProvider.html5Mode(true);
}]);
@svfat
svfat / gist:c3ca5169f838b3fd9b72
Created July 15, 2015 08:47
django robots.txt in urls
from django.http import HttpResponse
urlpatterns += url(r'^robots.txt$', lambda r: HttpResponse("User-agent: *\nDisallow: /", content_type="text/plain"))
@svfat
svfat / gist:5f312089da90ae49372c
Last active September 7, 2017 08:33
postgresql create new db
sudo su - postgres
psql
CREATE DATABASE myproject;
CREATE USER myproject WITH PASSWORD 'myproject';
ALTER ROLE myproject SET client_encoding TO 'utf8';
ALTER ROLE myproject SET default_transaction_isolation TO 'read committed';
ALTER ROLE myproject SET timezone TO 'UTC';
ALTER ROLE myproject CREATEDB;
GRANT ALL PRIVILEGES ON DATABASE myproject TO myproject;
\q
@svfat
svfat / resources_subscription.py
Last active February 21, 2016 13:36
Django TastyPie + dj-stripe API endpoint for subscriptions
from djstripe.models import Customer
from djstripe.settings import CANCELLATION_AT_PERIOD_END
from tastypie import http
def subscription(self, request, **kwargs):
self.method_check(request, ['get', 'post', 'delete'])
if request.user.is_authenticated():
user = request.user
customer = Customer.objects.get(subscriber=user)
if request.method == 'GET':
@svfat
svfat / enableswap.sh
Created April 24, 2016 20:37
Enable swapfile
#!/bin/sh
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
sysctl vm.swappiness=10
echo "vm.swappiness=10" >> /etc/sysctl.conf
sysctl vm.vfs_cache_pressure=50
echo "vm.vfs_cache_pressure=50" >> /etc/sysctl.conf