Skip to content

Instantly share code, notes, and snippets.

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

Dmitriy Nyashkin fdcore

🦄
Работаю круглосуточно
View GitHub Profile
@fdcore
fdcore / mailgun_sendmail.py
Created September 30, 2016 09:18
Send mail via Mailgun by requests on Python
import requests
def mailgun_sendmail(title='no title', content='', recipients=[]):
status = requests.post("https://api.mailgun.net/v3/DOMAIN/messages", # DOMAIN - your domain from mailgun
auth=("api", "key-2h2f...."), # YOR KEY with key-
data={"from": "postmaster@DOMAIN", # YOUR mail from mailgun
"to": recipients,
"subject": title,
"html": content
@fdcore
fdcore / pearson_correlation.php
Last active December 29, 2021 20:26
Php simple pearson correlation Function
<?php
function pearson_correlation($x,$y){
if(count($x)!==count($y)){return -1;}
$x=array_values($x);
$y=array_values($y);
$xs=array_sum($x)/count($x);
$ys=array_sum($y)/count($y);
$a=0;$bx=0;$by=0;
for($i=0;$i<count($x);$i++){
@fdcore
fdcore / image_squere.py
Created August 11, 2016 02:03
Create squere image on python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PIL import Image
def image_squere(filepath):
img = Image.open(filepath)
width, height = img.size
if width > height:
@fdcore
fdcore / isScrolledIntoView.js
Last active July 31, 2016 17:25
Load comments only if user viewed
// http://stackoverflow.com/a/488073
function isScrolledIntoView(elem)
{
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
// from http://stackoverflow.com/questions/18151877/javascript-shorten-large-numbers-force-decimal-places-and-choose-to-represent
function shortenNumber (num, decimalPlaces) {
var str,
suffix = '';
decimalPlaces = decimalPlaces || 0;
num = +num;
var factor = Math.pow(10, decimalPlaces);
@fdcore
fdcore / menu.html
Created February 11, 2016 05:57
Simple menu on twig and bootstrap
{% set current_page = "users" %}
<div class="col-md-3">
{% set menu = {'users': 'Users', 'logout': 'Logout', 'test': 'Test page'} %}
<div class="list-group">
{% for k, v in menu %}<a class="list-group-item {{ current_page == k?'active' }}" href="/{{ k }}">{{ v }}</a>{% endfor %}
</div>
</div>
@fdcore
fdcore / full_name_to_short.php
Created January 26, 2016 01:57
Конвертирует полное ФИО в короткое сокращение. Можно менять последовательность слов вторым параметром.
<?php
/*
Конвертирует полное ФИО в короткое сокращение. Можно менять последовательность слов вторым параметром.
@param $full_name Полное ФИО
@param $format формат, поддержиюваются буквы A,B,C для полных слов и a,b,c для сокращений в 1 букву
@author Dmitriy Nyashkin
*/
function full_name_to_short ($full_name, $format="A b. c.") {
$words = explode(" ", $full_name);
$format_keys = array("A", "B", "C");
@fdcore
fdcore / rating.js
Created December 22, 2015 23:48
Работа с звёздочками рейтинга, для FontAwsome, по клику присваивает полю значение.
/*
By [email protected]
<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>
<?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?
<?php
protected function parseCondition($field, $value = null, $join = '', $escape = true) {
if (is_string($field)) {
$operator = '';
if (strpos($field, ' ') !== false) {
list($field, $operator) = explode(' ', $field);
}