Skip to content

Instantly share code, notes, and snippets.

View alexsandro-xpt's full-sized avatar

Alexsandro Souza Pereira alexsandro-xpt

View GitHub Profile
@alexsandro-xpt
alexsandro-xpt / gist:3190082
Created July 27, 2012 19:38
WTF proxy limit CONNECT verb to SSL
try
{
//read the first line HTTP command
String httpCmd = clientStreamReader.ReadLine();
if (String.IsNullOrEmpty(httpCmd))
{
clientStreamReader.Close();
clientStream.Close();
return;
}
@alexsandro-xpt
alexsandro-xpt / Array.range.js
Created August 3, 2012 01:57 — forked from netojoaobatista/Array.range.js
ECMAScript 5 implementation of Python's range function
/**
* ECMAScript 5 implementation of Python's range function.
* @see {@link http://docs.python.org/release/1.5.1p1/tut/range.html}
* @param {Number} start
* @param {Number} end
* @param {Number} step
* @return {Array}
*/
Object.defineProperty(Array, "range", {
writable: false, configurable: false, enumerable: true,
@alexsandro-xpt
alexsandro-xpt / gist:3709231
Created September 12, 2012 19:19
Forçando o formato de uma data na cultura do estados unidos.
DateTime data;
DateTime.TryParse("10/01/2012", CultureInfo.GetCultureInfo("en-US").DateTimeFormat, DateTimeStyles.None ,out data);
Console.WriteLine(data.ToString("m"));
@alexsandro-xpt
alexsandro-xpt / gist:3739062
Created September 17, 2012 18:51
C# JavaScript unescape function
public static string unescape(string code)
{
var str = Regex.Replace(code, @"\+", "\x20");
str = Regex.Replace(str, @"%([a-fA-F0-9][a-fA-F0-9])", new MatchEvaluator((mach) => {
var _tmp = mach.Groups[0].Value;
var _hexC = mach.Groups[1].Value;
var _hexV = int.Parse(_hexC, System.Globalization.NumberStyles.HexNumber);
return ((char)_hexV).ToString();
}));
(function(p, r, o, x, y, s){
y = function(c){
return (c < r ? '' : y(parseInt(c / r))) + ((c = c % r) > 35 ? String.fromCharCode(c + 29) : c.toString(36))
};
if (!''.replace(/^/, String)) {
while (o--) {
s[y(o)] = x[o] || y(o)
}
x = [function(y){
return s[y]
@alexsandro-xpt
alexsandro-xpt / gist:3797518
Created September 28, 2012 01:43
Nostalgia: São Paulo/SP 26 de Agosto de 2004 | 03:50 da Matina
USE [moveis]
GO
/****** Object: Trigger [dbo].[organiza_registro] Date: 09/27/2012 22:50:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
Autor: Alexsandro Souza Pereira
Data: São Paulo/SP 26 de Agosto de 2004 | 03:50 da Matina
@alexsandro-xpt
alexsandro-xpt / todo.php
Created September 28, 2012 03:17 — forked from alganet/todo.php
A very small PHP todo list that saves to the database in 32 lines
<?php
//The actual implementation is just this file. Others are usage and tests.
class TodoList extends ArrayObject
{
const CREATE = 'CREATE TABLE IF NOT EXISTS tasks (name VARCHAR(32) PRIMARY KEY, status INT)';
const SELECT = 'SELECT * FROM tasks';
const INSERT = 'INSERT INTO tasks VALUES (?,?)';
const UPDATE = 'UPDATE tasks SET status = ? WHERE name = ?';
@alexsandro-xpt
alexsandro-xpt / BusinessDaysTest.php
Created September 28, 2012 03:18 — forked from netojoaobatista/BusinessDaysTest.php
Algorítimo idiota (e caro) para cálculo de dias úteis entre duas datas.
<?php
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'businessDays.php';
/**
* businessDays() test case.
*/
class BusinessDaysTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
parent::setUp();
@alexsandro-xpt
alexsandro-xpt / gist:3885498
Created October 13, 2012 17:40
Convert .net DateTime to JavaScript Timestamp and vice versa
var timestamp = (long)DateTime.UtcNow
.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
.TotalMilliseconds;
//http://stackoverflow.com/questions/1877788/javascript-date-to-c-sharp-via-ajax
var date = new DateTime(1970, 1, 1).AddTicks(timestamp * 10000);
public static Dictionary<char, int> teste(string url)
{
var arUrl = url.ToCharArray();
var gUrl = arUrl.GroupBy(n => n);
Console.WriteLine(gUrl.Count());
var pos = new Dictionary<char, int>();