Skip to content

Instantly share code, notes, and snippets.

View tihoho's full-sized avatar
❤️
Hey everyone!

Alex T tihoho

❤️
Hey everyone!
View GitHub Profile
@tihoho
tihoho / fewWords.php
Created June 8, 2017 13:46
How to get a few words from the string on PHP
<?php
function fewWords($str, $limit) {
return rtrim(implode(' ', array_slice(explode(' ', $str), 0, $limit)), ',-');
}
// Example:
$str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt';
<?php
function matrix($x = 3, $y = 3) {
$_matrix = [];
for($_x = 0; $_x < $x; $_x++) {
for($_y = 0; $_y < $y; $_y++) {
$_matrix[$_x][$_y] = mt_rand(1,5);
}
}
return $_matrix;
<?php
session_start();
$count = 1;
if(isset($_SESSION['counter'])) {
$count = intval($_SESSION['counter']);
$_SESSION['counter']++;
-- юзеры
CREATE TABLE `users` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(32) NULL DEFAULT 'No_name',
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
;
-- хобби
<?php
// Входящие данные
$article = 'hp'; // артикул товара
$sum = 3563; //Сумма (для теста тут принтер hp + 4 катриджа: hpb*3 + hpr*1)
// принтеры
$printersPrice = [
'canon' => 1000,
'hp' => 2000,
@tihoho
tihoho / remove-not-unique.sql
Created January 6, 2018 13:39
Remove not-uniuqe values in table field
delete from MYTABLE where id in (
select id from (
select id, count(*) 'c' from MYTABLE where 1 group by MYFIELD having count(`c`) > 1
) as `items`
)
<?php
namespace common\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\User;
use common\models\Balance;
@tihoho
tihoho / backside.php
Created February 10, 2018 19:44
Search a Earth back-side by lat-lon point
<?php
function backSide($lat, $lon) {
$lat *= -1;
$lon = $lon < 0 ? $lon + 180 : $lon - 180;
return [$lat, $lon];
}
@tihoho
tihoho / media-query.css
Created April 27, 2018 21:35 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
Stopping spam is a constant fight and due to this, your account has restrictions specifically on port 25. However, you are be able to use mail services using ports 587, 993, 995 and 465. You will need to open these ports in your firewall. Here is our guide to common iptables commands:
https://www.digitalocean.com/community/tutorials/iptables-essentials-common-firewall-rules-and-commands#service-mail
We realize this is inconvenient, but many customers in your position move their mailing activities to a third party service such as SendGrid or similar which processes such mail separately from their droplet. I'm sorry for the frustration but we're not able to lift this port restriction at this time.
In terms of a workaround, here are a few alternatives:
1. Utilize port 587 for SMTP relay via another mail provider, for example G Suite/Gmail, Mailgun, etc. We have a guide on doing so using Postfix here: