Skip to content

Instantly share code, notes, and snippets.

@inogo
inogo / gist:1460667
Created December 11, 2011 13:38
simple encoding detection
<?php
function detect_encoding($string)
{
foreach (array('UTF-8', 'Windows-1251') as $enc) {
$sample = @iconv($enc, $enc, $string);
if (md5($sample) == md5($string))
return $enc;
}
return false;
@inogo
inogo / Hashes.cs
Created December 23, 2011 14:15
SHA1
using System;
using System.Text;
using System.Security.Cryptography;
static class Hashes
{
public static string SHA1(string text)
{
byte[] buffer = Encoding.UTF8.GetBytes(text);
var sha1 = new SHA1CryptoServiceProvider();
@inogo
inogo / SQLyogTunnel.php
Created November 21, 2012 07:08 — forked from anonymous/SQLyogTunnel.php
SQLyog HTTP Tunnel
<?php
/*
SQLyog
Copyright 2003-2006, Webyog
http://www.webyog.com
HTTP Tunneling Page
This page exposes the MySQL API as a set of web-services which is consumed by SQLyog - the most popular GUI to MySQL.
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "from@domain.tld";
$to = "to@domain.tld";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
@inogo
inogo / modX_mobileContext.php
Last active August 29, 2015 14:06
MODX Mobile Switch Context Plugin
<?php
/* see:
* http://rtfm.modx.com/revolution/2.x/administering-your-site/contexts/using-one-gateway-plugin-to-manage-multiple-domains
* "mobileContext" - mobile version context name
*/
if (!isset($scriptProperties['mobileContext']) || empty($scriptProperties['mobileContext'])) {
return;
}
/* don't execute if in the Manager */
if ($modx->context->get('key') == 'mgr') {
@inogo
inogo / client_ip.php
Created September 20, 2014 17:16
Get client IP address
<?php
function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
@inogo
inogo / modx_nl2list.php
Created November 13, 2014 15:31
MODX nl2list output filter
<?php
parse_str($options, $options);
$options = array_merge(array(
'ul' => 0
), $options);
$lines = preg_split('/\n\r?/', trim($input));
$output = '<li>' . implode('</li><li>', $lines) . '</li>';
if ($options['ul']) {
<!-- chunk: tpl.catalogFilter -->
<div class="filter clearfix">
[[!initProductsFilter]]
<form action="" method="get" class="filter-form[[+filter.active:notempty=` filter-active`]]">
<div class="filter-buttons">
<button type="submit" class="btn">Фильтр</button>
<button type="reset" class="btn filter-reset">Сбросить</button>
</div>
<div class="filter-rows">
<div class="filter-row">
<?php
class InvoiceGenerator
{
/**
* @var modX
*/
public $modx;
public $file_name_prefix = 'invoice_';
@inogo
inogo / modx-snippets.php
Last active November 23, 2016 03:42 — forked from christianhanvey/modx-snippets.php
Useful snippets for MODX Revo
Snippet: [[SnippetName]]
Chunk: [[$ChunkName]]
System Setting: [[++SettingName]]
TV: [[*fieldName/TvName]]
Link tag: [[~PageId? &paramName=`value`]]
Placeholder: [[+PlaceholderName]]
<?php