Skip to content

Instantly share code, notes, and snippets.

View f0t0n's full-sized avatar

Eugene Naydenov f0t0n

View GitHub Profile
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<msub>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">V</mi>
</mrow>
<mn>1</mn>
</msub>
<mo>&#x00D7;<!-- × --></mo>
<msub>
<mrow class="MJX-TeXAtom-ORD">
\frac{1}{(\sqrt{\phi \sqrt{5}}-\phi) e^{\frac25 \pi}} =
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
{1+\frac{e^{-8\pi}} {1+\ldots} } } }
<?php
interface ApiErrorCode {
const WRONG_ACTION = 0;
const WRONG_PARAMETERS_SET = 1;
public function getError();
}
interface ChartusApiErrorCode extends ApiErrorCode {
const WRONG_USER_CREDENTIALS = 2;
const CANT_RETRIEVE_AUTH_TOKEN = 3;
@f0t0n
f0t0n / maintenance.php
Created May 22, 2012 10:11
Add this file to protected/config directory
<?php return false;
<?php
// domain => apiKey dictionary
$allowedDomains = array(
'domain-from.com' => 's0m3d0ma1n1d',
);
$host = parse_url($_SERVER['HTTP_ORIGIN'], PHP_URL_HOST);
if(!empty($host)
&& isset($allowedDomains[$host])
&& isset($_POST['apiKey'])
&& $allowedDomains[$host] == $_POST['apiKey']) {
@f0t0n
f0t0n / service_example.php
Created May 30, 2012 15:07
CORS example (server side).
<?php
if(empty($_SERVER['HTTP_ORIGIN'])) {
die;
}
defined('LOG_DIR') OR define('LOG_DIR', dirname(__FILE__) . '/log/');
// domain => apiKey dictionary
$allowedDomains = array(
'qualify-test-site.local' => 's0m3d0ma1n1d',
);
$host = parse_url($_SERVER['HTTP_ORIGIN'], PHP_URL_HOST);
@f0t0n
f0t0n / gist:2836917
Created May 30, 2012 15:14
Request example
array (
'apiKey' => 's0m3d0ma1n1d',
'domain' => 'qualify-test-site.local',
'userActions' =>
array (
0 =>
array (
'htmlElement' =>
array (
'element_id' => 'test-form',
@f0t0n
f0t0n / Bcrypt.php
Created June 7, 2012 18:43
PHP Bcrypt implementation
<?php
/*
By Marco Arment <me@marco.org>.
This code is released in the public domain.
THERE IS ABSOLUTELY NO WARRANTY.
Usage example:
// In a registration or password-change form:
<?php
if(!empty($labelNegativeFilter)) {
$criteria->addCondition('
t.id NOT IN (
SELECT bug_id FROM {{bug_by_label}}
WHERE label_id IN (
' . implode(',', $labelNegativeFilter) .'
)
)
');
@f0t0n
f0t0n / list2dict.py
Created August 12, 2012 14:22
Converts lists of bookmarks in directories to dictionaries.
#!/usr/bin/env python
def list_to_dict(pages):
return {page['name']: page for page in pages}
def convert_bookmarks(bookmarks):
for root, directory in bookmarks['roots'].iteritems():
directory['children'] = list_to_dict(directory['children'])
if __name__ == '__main__':