Skip to content

Instantly share code, notes, and snippets.

View samdark's full-sized avatar
🛠️
Improving everything

Alexander Makarov samdark

🛠️
Improving everything
View GitHub Profile

Resetting OpenCFP

If you've used OpenCFP for a conference and want to use it next year you have to reset all talks. It is a good idea to keep users though.

That's how to do it:

  1. Backup your current database.
  2. Adjust dates in config/production.yml.
  3. Clean up database:
@samdark
samdark / github-post-receive.php
Last active October 11, 2019 10:05
Simple GitHub post-receive PHP hook
<?php
function cidr_match($ip, $ranges)
{
$ranges = (array)$ranges;
foreach($ranges as $range) {
list($subnet, $mask) = explode('/', $range);
if((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) {
return true;
}
}
@samdark
samdark / composer.lock
Created June 11, 2019 13:47
yii-demo 2019.06.11
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3c5ebbee4c63d262290c75bc24c2e892",
"packages": [
{
"name": "cebe/markdown",
-- Cleans up IPB 3 database before importing it into another forum engine
-- tbl_* are project specific, could be removed
-- Remove banned members and members with no posts
delete m
from ipb_members m
left join tbl_user u on u.id = m.member_id
where
(
member_banned = 1
<?php
$db = new PDO('mysql:host=localhost;dbname=rmc2', 'root');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
function benchmark($callback){
$start = microtime(true);
for ($i = 0; $i < 100; $i++)
$callback();
return microtime(true) - $start;
}
@samdark
samdark / yii_functions_sql.php
Created June 21, 2012 19:33
Yii: handy functions to use Yii with raw SQL
<?php
/**
* Escapes values
*
* @param array $values array of values to escape
* @return string string ready to be included into SQL statement
* @throws CException if one of the values isn't a scalar
*/
function escape($values)
{
@samdark
samdark / Object.php
Created May 30, 2012 12:22
Yii2, Object
<?php
/**
* Object class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
@samdark
samdark / phpunit_array_assertions.php
Created October 10, 2016 11:21
PHPUnit array assertions
public static function assertArrayStructure($keys, $array)
{
$arrayKeys = array_keys($array);
$missing = array_diff($keys, $arrayKeys);
$unexpected = array_diff($arrayKeys, $keys);
$message = 'Keys are wrong.';
if ($missing !== []) {
$message .= ' Missing: ' . implode(', ', $missing) . '.';
@samdark
samdark / Sam Dark.icls
Created August 11, 2016 13:25
My PhpStorm color schema
<scheme name="Sam Dark" version="142" parent_scheme="Default">
<option name="LINE_SPACING" value="1.05" />
<option name="EDITOR_FONT_SIZE" value="15" />
<option name="EDITOR_LIGATURES" value="true" />
<option name="CONSOLE_FONT_NAME" value="Monospaced" />
<option name="CONSOLE_FONT_SIZE" value="13" />
<option name="EDITOR_FONT_NAME" value="Fira Code" />
<colors>
<option name="WHITESPACES" value="f2f2f2" />
</colors>
@samdark
samdark / HmvcController.php
Created August 3, 2011 22:36
Yii: Simple HMVC
<?php
/**
* Yii, simple HMVC
*/
class HmvcController extends Controller
{
public function actionIndex()
{
echo $this->execute('/hmvc/do/id/123');
}