Skip to content

Instantly share code, notes, and snippets.

View devoto13's full-sized avatar

Yaroslav Admin devoto13

View GitHub Profile
@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: подсвечивать четные строки другим цветом
@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');
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace sska
{
class Tuple
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
@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;
}
@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 / 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="[email protected]"
domain="$1"
branch="$2"