Skip to content

Instantly share code, notes, and snippets.

View fdcore's full-sized avatar
🦄
Работаю круглосуточно

Dmitriy Nyashkin fdcore

🦄
Работаю круглосуточно
View GitHub Profile
@fdcore
fdcore / fabfile.py
Last active November 24, 2020 08:57
backup files and sql from servers, use fabric python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# run: fab backup
__author__ = 'fdcore'
from fabric.api import env, run, get
from datetime import datetime
import os
env.hosts = [
@fdcore
fdcore / twig.html
Created June 10, 2014 00:20
Cool features for title if use twig template engine
<title>{% block title %}{{ title|default('My Default Title') }}{% endblock %}</title>
<!--
in code
$tags['title'] = 'my title';
or
{% block title %}my title{% endblock %}
-->
@fdcore
fdcore / curl.php
Last active August 29, 2015 14:16
Use CURL in PHP
<?php
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:37.0) Gecko/20100101 Firefox/37.0');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_VERBOSE, true);
@fdcore
fdcore / stars.php
Created March 28, 2015 00:18
Функция генерации звёзд по рейтингу, 10 бальный рейтинг => в 5 звёзд
<?php
function stars ($string, $color_class='') {
$html = '<ul class="rating '.$color_class.'">';
$avg5 = round($string / 2, 1);
for($i=0; $i <= 5; $i++){
$x = $i + 1;
@fdcore
fdcore / short_date.php
Last active August 29, 2015 14:17
Выводит время в формате "сегодня", "вчера".
<?php
// принимает время в unix timestamp
// возвращает текст (сегодня в 01:23, вчера в 12:34, 3 мар 2015 в 23:45)
function short_date($a) {
date_default_timezone_set('Europe/Moscow');
$ndate = date('d.m.Y', $a);
$ndate_time = date('H:i', $a);
$ndate_exp = explode('.', $ndate);
$nmonth = array('','янв','фев','мар','апр','мая','июн','июл','авг','сен','окт','ноя','дек');
<?php
if ( ! function_exists('url_title'))
{
/**
* Create URL Title
*
* Takes a "title" string as input and creates a
* human-friendly URL string with a "separator" string
* as the word separator.
@fdcore
fdcore / uuid.php
Last active March 2, 2019 03:26
Encode long UUID to short binary string like youtube hash
<?php
// echo uuid_encode('cd76b808-4017-4965-b9b1-2dbcf857e405');
function uuid_encode($uuid){
$binary = pack("h*", str_replace('-', '', $uuid));
$binary = base64_encode($binary);
$binary = str_replace('/', '_', $binary);
$binary = str_replace('=', '', $binary);
return $binary;
<?php
protected function parseCondition($field, $value = null, $join = '', $escape = true) {
if (is_string($field)) {
$operator = '';
if (strpos($field, ' ') !== false) {
list($field, $operator) = explode(' ', $field);
}
<?php
function get_win($arr){
$chance = rand(0, 100);
$keys = array_keys($arr);
$total = count($keys);
if($total == 0) return false;
$inter_stopper = 100;// DDOS FIX?
@fdcore
fdcore / rating.js
Created December 22, 2015 23:48
Работа с звёздочками рейтинга, для FontAwsome, по клику присваивает полю значение.
/*
By dmitriy@nyashk.in
<input type="hidden" name="rate" id="star_rate" value="0">
<div class="stars empty" data-id="rate">
<ul>
<li><i class="fa fa-star-o"></i></li>
<li><i class="fa fa-star-o"></i></li>
<li><i class="fa fa-star-o"></i></li>