Skip to content

Instantly share code, notes, and snippets.

View ar7n's full-sized avatar
🪲
working hard

Arseny Sysolyatin ar7n

🪲
working hard
View GitHub Profile
from django.db import connection
def idseq(model_class):
return '{}_id_seq'.format(model_class._meta.db_table)
def get_next_id(model_class):
cursor = connection.cursor()
sequence = idseq(model_class)
cursor.execute("select nextval('%s')" % sequence)
row = cursor.fetchone()
@ar7n
ar7n / create-db.sql
Created February 11, 2019 08:41
Create Postgres DB with RU locale
CREATE DATABASE "dbname"
WITH OWNER "postgres"
ENCODING 'UTF-8'
LC_COLLATE = 'ru_RU.UTF-8'
LC_CTYPE = 'ru_RU.UTF-8'
TEMPLATE = template0;
@ar7n
ar7n / README.md
Created December 13, 2018 11:48 — forked from phpdude/README.md

Simplest Async Email Backend for Django

What is this?

It is simplest email backend for Django which supports async email delivery in parallel threads. Keep it simple! It has various analogs, you can google for it yourself.

Requirements

Django async email backend requires futures library. So you need to install it with pip install futures.

@ar7n
ar7n / Countries.js
Created November 20, 2016 13:11 — forked from JedWatson/Countries.js
Example of how to use the filters option for Relationship fields
// A global file to provide the countries and cities
exports.countries = [{
name: 'Australia',
cities: ['Melbourne', 'Sydney', 'Canberra']
}, {
name: 'España',
cities: ['Madrid', 'Barcelona', 'Sevilla']
}, {
name: 'Italia',
@ar7n
ar7n / API-Auth-With-KeystoneJS.md
Created November 20, 2016 13:11 — forked from JedWatson/API-Auth-With-KeystoneJS.md
API Auth with KeystoneJS

To implement API authentication in KeystoneJS, you need the following:

For key based authentication

  • Middleware that validates the key in the request body or a header

For session based authentication

  • An endpoint that handles signin
  • An endpoint that handles signout
@ar7n
ar7n / smoth-page-loader.js
Created April 22, 2016 13:16
Smooth page loader. Fade out and fade in for all pages.
!function() {
var overlay;
var timeout = setInterval(function(){
if (document.body) {
var style = document.createElement('style');
style.innerText = '@keyframes preloader-spin {from {transform: rotate(0deg);} to {transform: rotate(360deg);}}';
document.head.appendChild(style);
overlay = document.createElement('div');
overlay.style.cssText = "position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000; background: #ffffff; opacity: 1; transition: opacity 0.3s ease-in, z-index 0.3s step-end";
var preloader = document.createElement('img');
@ar7n
ar7n / sendmail.php
Created February 4, 2016 13:56
Send email by php
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf-8";
$headers[] = "From: Sender Name <sender@domain.com>";
$headers[] = "Bcc: JJ Chong <bcc@domain2.com>";
$headers[] = "Reply-To: Recipient Name <receiver@domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
@ar7n
ar7n / regexp.js
Created February 4, 2016 13:30
Regexps
# Email
/^(([a-zA-Z]|[0-9])|([-]|[_]|[.]))+[@](([a-zA-Z0-9])|([-])){2,63}[.](([a-zA-Z0-9]){2,63})+$/gi;
# Russian phone number
/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/g;
@ar7n
ar7n / count-ip-requests.sh
Created February 4, 2016 11:55
Count the number of requests from IPs
cat access.log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20
@ar7n
ar7n / KeystoneApiExample.md
Created January 22, 2016 10:26 — forked from JedWatson/KeystoneApiExample.md
Example of how to scaffold API endpoints for Posts in a Keystone project (based on the yo keystone example).

This is an example of how to scaffold API endpoints to list / get / create / update / delete Posts in a Keystone website.

It's a modification of the default project created with the yo keystone generator (see https://github.com/JedWatson/generator-keystone)

Gists don't let you specify full paths, so in the project structure the files would be:

routes-index.js        -->    /routes/index.js         // modified to add the api endpoints
routes-api-posts.js    -->    /routes/api/posts.js     // new file containing the Post API route controllers