Skip to content

Instantly share code, notes, and snippets.

View devoto13's full-sized avatar

Yaroslav Admin devoto13

View GitHub Profile
@devoto13
devoto13 / addvhost.sh
Last active December 20, 2015 17:19
Shell-script for creating virtual hosts (with directory structure) for LAMP on Ubuntu.Place somewhere on the PATH, for example at /usr/local/bin.Usage: sudo addvhost <hostname> <branch>
#!/bin/bash
if [ $# -lt 2 ] ; then
echo "Usage: sudo addvhost <hostname> <branch>";
exit 0;
fi
email="admin@example.com"
domain="$1"
branch="$2"
@devoto13
devoto13 / relative_format.php
Last active December 26, 2015 07:19
PHP: format relative date
<?php
function formatDate($date, $point = 'now') {
$point = date_create($point);
$date = date_create_from_format('Y-m-d H:i:s', $date);
$interval = date_diff($point, $date);
$delta = $point->getTimestamp() - $date->getTimestamp();
$SECOND = 1;
$MINUTE = 60 * $SECOND;
@devoto13
devoto13 / age_format.php
Last active December 26, 2015 12:49
PHP: format human age
<?php
function formatAge($date, $point = null) {
$date = DateTime::createFromFormat('Y-m-d', $date);
$point = $point ? DateTime::createFromFormat('Y-m-d', $point) : new DateTime();
$interval = $date->diff($point);
if ($interval->format('%r%a') <= 0) {
return false;
}
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import Table, Column, Integer, ForeignKey
from sqlalchemy.orm import relationship, backref
engine = create_engine('sqlite:///:memory:', echo=True)
Base = declarative_base()
Base.metadata.bind = engine
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace sska
{
class Tuple
@devoto13
devoto13 / dollars.js
Created November 26, 2014 18:41
Dollars amount real-time update
(function ($) {
var DOLLARS = 20;
$.fn.dollars = function () {
$(this).each(function () {
var $table = $(this);
$table.find('tr:first-child th:not(:first-child)').each(function (index) {
var $label = $('<span/>').appendTo($(this)),
$fields = $table.find('td:nth-child(' + (index + 2) + ') input');
@devoto13
devoto13 / table.js
Last active August 29, 2015 14:17
table.js
/*
* Library for working with db tables.
*
* Config options:
*
* container string: идентификатор контейнера для таблицы
* hasInsertButton bool: показывать ли кнопку добавления записи
* insertButtonText string: текст кнопки добавления
* enableSorting bool: включить сортировку
* hightlightOddRows bool: подсвечивать четные строки другим цветом
def set_title(self, title: str=None):
self.title = title
@devoto13
devoto13 / hatch.py
Created July 30, 2015 10:24
Modified hatch() method for locust
def hatch():
sleep_time = 1.0 / self.hatch_rate
while True:
if not bucket:
if sum(occurrence_count.values()) < spawn_count:
gevent.sleep(0.5)
continue
else:
logger.info("All locusts hatched: %s" % ", ".join(
["%s: %d" % (name, count) for name, count in occurrence_count.iteritems()]))
Internal Server Error: /v0.5/channels/1/posts/
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 111, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/views/decorators/csrf.py", line 57, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/rest_framework/viewsets.py", line 87, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/rest_framework/views.py", line 466, in dispatch
response = self.handle_exception(exc)