Skip to content

Instantly share code, notes, and snippets.

View ruslankonev's full-sized avatar
:octocat:
Make a good things

Ruslan Konev ruslankonev

:octocat:
Make a good things
View GitHub Profile
@ruslankonev
ruslankonev / chaching.php
Created September 18, 2013 08:31
Laravel Кеширование постов
<?php
$articles = Article::remember(5)->get(); // works great!
?>
@ruslankonev
ruslankonev / addpic.php
Created September 18, 2013 09:33
Автоматическое добавление миниатюры картинки из поста
<?php function avtomaticheskaya_miniatura() {
global $post;
$already_has_thumb = has_post_thumbnail($post-->ID);
// проверка на наличие миниатюры посте
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
// делаем условие проверку на наличеи картинки
if ($attached_image) {
<?php
include("../wp-includes/class-IXR.php");
$client = new IXR_Client('http://www.example.com/xmlrpc.php');
if (!$client->query('wp.getCategories','', 'admin',’password’)) {
die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
}
$response = $client->getResponse();
$content['title'] = 'Test Draft Entry using MetaWeblog API';
@ruslankonev
ruslankonev / tox.sh
Created February 10, 2014 09:09 — forked from urras/tox.sh
#!/bin/bash
## wget -O tox.sh https://gist.github.com/fr0stycl34r/6690783/raw && chmod +x ./tox.sh && ./tox.sh
# By cl34r and notadecent
rootcheck() {
if [ "id -u $USERNAME" = "0" ]; then
echo "Please do not run this script as root"
exit 1
fi
}
# Check if script is being run as root
#!/usr/bin/env bash
# I recently had to install MySQL 5.6 on Ubuntu 12.04 from a .deb package on the MySQL website. It seems that either the package has been updated recently or nobody uses this method to install so I ended up running into endless problems. Through trial and error I found the following method works for me.
#Install libaio-dev:
sudo apt-get install libaio-dev
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.12-debian6.0-x86_64.deb/from/http://cdn.mysql.com/ -O mysql-server.deb
#Now install your package(mine was enterprise edition, community may have a different filename):
sudo dpkg -i mysql-server.deb
@ruslankonev
ruslankonev / installer.sh
Created April 29, 2014 06:44
Установка LAMP server на Ubuntu с nodejs #php5.4/5.5
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
# For 5.5, needs Apache 2.4
sudo add-apt-repository -y ppa:ondrej/php5
#php 5.4
#sudo add-apt-repository -y ppa:ondrej/php5-oldstable
@ruslankonev
ruslankonev / clearpostfix.sh
Created May 30, 2014 13:48
Clear Filed Mails from postfix and send to email
postqueue -p | egrep '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b' > failsmail.txt
echo "filed mails" | mail -a failsmail.txt -s "SPAM emails" career2012.content@gmail.com
@ruslankonev
ruslankonev / findallmailsonpage.js
Last active August 29, 2015 14:02
Find and unique all emails in page (javascript)
var body = window.document.body.innerHTML;
//var body = document.querySelector('td.Bu').innerHTML
var regular = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/ig;
var arrayUnique = function(a) {
return a.reduce(function(p, c) {
if (p.indexOf(c) < 0) p.push(c);
return p;
}, []);
};
arrayUnique(body.match(regular));

Setup

  • Add this file to application/libraries (or, if you are already extending the Validator class, add the contents there).
  • Remove Validator alias from config/application.php in order to avoid conflicts.
  • Add "required_if_attribute" => "The :attribute field is required." to application/language/[language]/validation.php.

Usage

Define the rule using:

required_if_attribute:[field],[operator],[value]

#!/bin/bash
#
# Lee Robert's Base Ubuntu Installation script for use on Digital Ocean (Or any other ubuntu install really.)
# Made and tested with Ubuntu 13.04 64bit
#
# USAGE: bash hardenUbuntu.sh
#
# Steps:
# 01. Secure Root User
# 02. Make .bashrc print out pretty colors (and root's prompt will be red)