Skip to content

Instantly share code, notes, and snippets.

Avatar

Demis Bellot mythz

View GitHub Profile
@mythz
mythz / gist:744701
Created Dec 17, 2010
Get IP address of WCF Service
View gist:744701
public static IPAddress GetIpAddress(System.ServiceModel.OperationContext context)
{
var prop = context.IncomingMessageProperties;
if (context.IncomingMessageProperties.ContainsKey(System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name))
{
var endpoint = prop[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name]
as System.ServiceModel.Channels.RemoteEndpointMessageProperty;
if (endpoint != null)
{
return IPAddress.Parse(endpoint.Address);
@mythz
mythz / gist:750202
Created Dec 21, 2010
JavaScript createTableFn
View gist:750202
var createTableWithCaption = function (id, caption, tableStyle)
{
var sb = "<div class='sd-info'><table id='" + id + "' class='itfa_sectionbody' style='" + tableStyle + "'>";
if (caption) sb += "<caption>" + caption + "</caption>";
return sb;
}
var createTableFn = function (id, fieldNames, caption, tableStyle, tfoot)
{
@mythz
mythz / AsyncServiceClientTests
Created Jan 15, 2011
Passing tests for ServiceStack.NET's new C# Async Web Service Clients
View AsyncServiceClientTests
[TestFixture]
public class AsyncServiceClientTests
{
private const string ListeningOn = "http://localhost:82/";
ExampleAppHostHttpListener appHost;
[TestFixtureSetUp]
public void OnTestFixtureSetUp()
{
@mythz
mythz / NonBlockingReadBufferedStream alpha
Created Jan 26, 2011
Naive Example of a 1 Read + 1 Write thread buffer
View NonBlockingReadBufferedStream alpha
/* Incomplete un-tested buffered implementation designed to accomodate 1 write thread and 1 read thread only
* Not implemented yet, but is expected to be pooled.
*/
public class NonBlockingReadBufferedStream
: Stream, IEnumerable<Action<Action<object>, Action<Exception>>>, IDisposable
{
private const int MtuAppSize = 1450;
private const int BufferAllocationSize = 32 * 1024;
internal int ResetClearsBufferOfMaxSize = 4 * 1024 * 1024; //4MB
@mythz
mythz / Working Redis Example
Created Feb 26, 2011
Refactored to working example
View Working Redis Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack;
using ServiceStack.Common;
using ServiceStack.Common.Extensions;
using ServiceStack.Common.Utils;
using ServiceStack.Redis;
using ServiceStack.Redis.Generic;
@mythz
mythz / gist:844885
Created Feb 26, 2011
Refactored to working example
View gist:844885
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack;
using ServiceStack.Common;
using ServiceStack.Common.Extensions;
using ServiceStack.Common.Utils;
using ServiceStack.Redis;
using ServiceStack.Redis.Generic;
@mythz
mythz / install_nginx.sh
Created Feb 28, 2011
Install Nginx 0.9.5 on OSX
View install_nginx.sh
#!/bin/bash
## DOWNLOADS
sudo curl -OL h ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz > /usr/local/src/pcre-8.12.tar.gz
sudo curl -OL h http://nginx.org/download/nginx-0.9.5.tar.gz > /usr/local/src/nginx-0.9.5.tar.gz
## Install PCRE
sudo mkdir -p /usr/local/src
cd /usr/local/src
tar xvzf pcre-8.12.tar.gz
@mythz
mythz / StringBuffer.js
Created Mar 4, 2011
Stand-alone version Google goog.string.StringBuffer for efficient string catenation on all browsers
View StringBuffer.js
var hasScriptEngine = 'ScriptEngine' in window;
var HAS_JSCRIPT = hasScriptEngine && window['ScriptEngine']() == 'JScript';
var IS_IE = HAS_JSCRIPT;
var StringBuffer = function(opt_a1, var_args) {
this.buffer_ = HAS_JSCRIPT ? [] : '';
if (opt_a1 != null) {
this.append.apply(this, arguments);
}
@mythz
mythz / FastJQueryForIE7
Created Mar 8, 2011
jQuery is very slow at handling poor browsers, this script added a 7.8x perf improvement
View FastJQueryForIE7
/*
* Faster jQuery DOM traversal for <= IE7.
* Usage:
* $Q() is a drop-in replacement for $(). Returns same jQuery object.
*
* //$Q = $; //Un-comment, to switch to use jQuery for benchmark comparisons
* My avg benchmarks in IE7 for traversing a 20x30 table was:
* 786ms vs 6140.67ms - Chrome can do it natively in 28ms
*
* Limitations:
@mythz
mythz / js-utils.js
Created Mar 8, 2011
javascript utils
View js-utils.js
var fromDtoDate = function(dateStr) {
if (!dateStr) return null;
return new Date(parseFloat(/Date\(([^)]+)\)/.exec(dateStr)[1]));
}
var formatDtoDate = function(dateObj) {
if (!dateObj) return "";
if (dateObj != typeof "date") dateObj = fromDtoDate(dateObj);
var day = dateObj.getDate(), month = dateObj.getMonth() + 1;
if (day < 10) day = "0" + day;