Skip to content

Instantly share code, notes, and snippets.

View mirhmousavi's full-sized avatar

Mirhossein Mousavi mirhmousavi

View GitHub Profile
@j4mie
j4mie / normalise.py
Created August 30, 2010 12:44
Normalise (normalize) unicode data in Python to remove umlauts, accents etc.
# -*- coding: utf-8 -*-
import unicodedata
""" Normalise (normalize) unicode data in Python to remove umlauts, accents etc. """
data = u'naïve café'
normal = unicodedata.normalize('NFKD', data).encode('ASCII', 'ignore')
print normal
@mbijon
mbijon / xss_clean.php
Last active November 1, 2022 03:23
XSS filtering in PHP (cleans various UTF encodings & nested exploits)
<?php
/*
* XSS filter, recursively handles HTML tags & UTF encoding
* Optionally handles base64 encoding
*
* ***DEPRECATION RECOMMENDED*** Not updated or maintained since 2011
* A MAINTAINED & BETTER ALTERNATIVE => kses
* https://github.com/RichardVasquez/kses/
*
* This was built from numerous sources
@hakre
hakre / unicode-encode-utf8.php
Created April 10, 2012 14:05
Unicode Codepoint to UTF-8
<?php
/**
* @see Unicode 6.0.0 Ch2 General Structure, rfc3629
* @param int|string $codepoint e.g. 0xC9 / "U+00C9"
* @return string
*/
function unicodeCodePointToUTF8($codepoint)
{
is_string($codepoint) && sscanf($codepoint, 'U+%x', $codepoint);
if ($codepoint < 0) {
@arosenhagen
arosenhagen / magento-code-snippets.md
Last active April 8, 2024 09:21
[magento] - code snippets

Magento Code Snippets

Download extension manually using mage

./mage config-set preferred_state stable
./mage clear-cache
./mage sync
./mage download community Module_Name
@Maks3w
Maks3w / gist:3097685
Created July 12, 2012 11:51
in_array vs foreach
<?php
$value = 'A';
$haystack = array('test', 0, 'A');
$strict = false;
$s = microtime(true);
in_array($value, $haystack, $strict);
$e = microtime(true);
echo ' ' . ($e - $s) . PHP_EOL;
@hyone
hyone / gist:3950460
Created October 25, 2012 04:49
Multiple async HTTP requests by Haskell
{-# LANGUAGE FlexibleContexts #-}
import Data.Conduit
import qualified Data.Conduit.List as CL
import Network.HTTP.Conduit
import Control.Concurrent.Async (mapConcurrently)
import Control.Concurrent.MVar
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Control (MonadBaseControl)
@Nurdok
Nurdok / python_conversion.md
Last active July 11, 2024 15:00
Python Conversion

Python Number Conversion Chart

From To Expression
@jonmchan
jonmchan / Calculator.php
Created January 17, 2013 19:15
PHP Unit Testing Example Code
<?php
// Calculator.php
class Calculator {
public function getNumberFromUserInput() {
// complicated function to get number from user input
}
public function printToScreen($value) {
// another complicated function
}
@pkmishra
pkmishra / middlewares.py
Last active November 8, 2020 05:26
Scrapy middlewares for random agent list and proxy server usage.
import os
import random
from scrapy.conf import settings
class RandomUserAgentMiddleware(object):
def process_request(self, request, spider):
ua = random.choice(settings.get('USER_AGENT_LIST'))
if ua:
request.headers.setdefault('User-Agent', ua)
class ProxyMiddleware(object):
@nikic
nikic / php_evaluation_order.md
Last active October 19, 2021 05:47
Analysis of some weird evaluation order in PHP

Order of evaluation in PHP

Yesterday I found some people on my [favorite reddit][lolphp] wonder about the output of the following code:

<?php

$a = 1;
$c = $a + $a++;