Skip to content

Instantly share code, notes, and snippets.

Dexter M Haslem DexterHaslem

View GitHub Profile
@DexterHaslem
DexterHaslem / rawnet2ip.rb
Created Nov 15, 2010
Convert 4 network bytes into an IP address
View rawnet2ip.rb
# bytes should be a string of bytes from a network response etc
# raw_data = <4 raw bytes>
IPAddr.new(raw_data.unpack("N")[0], Socket::AF_INET)
@DexterHaslem
DexterHaslem / parseservers.rb
Created Nov 15, 2010
A simple script that demonstrates parsing game servers from a master server response
View parseservers.rb
#!/usr/bin/env ruby
# encoding: utf-8
require 'socket'
require 'ipaddr'
UDPSocket.new.tap do |sock|
sock.connect "dpmaster.deathmask.net", 27950
sock.send "\xFF\xFF\xFF\xFFgetservers Warsow 11 full empty \0", 0
if data = sock.recvfrom(2**16)[0]
View gist:702347
<?php
// - hardcoded auth header
$username = "dude";
$password = "Topsecret";
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
( $_SERVER['PHP_AUTH_USER'] != $username ) || ( $_SERVER['PHP_AUTH_PW'] != $password ) )
{
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate:Basic realm="Record admin"');
@DexterHaslem
DexterHaslem / gist:1348944
Created Nov 8, 2011
debug print streaming web request
View gist:1348944
let printStreamingWebReq (url : string, postContent : string) =
let req = WebRequest.Create url :?> HttpWebRequest
req.Method <- "POST"
req.Proxy <- null
let postDataEncoded = ASCIIEncoding.ASCII.GetBytes(postContent)
let len : int64 = int64 postDataEncoded.Length
req.ContentLength <- len
let reqStream = req.GetRequestStream()
reqStream.Write(postDataEncoded, 0, postDataEncoded.Length)
use response = req.GetResponse()
View gist:2395012
open System
type bar =
{ Symbol : string; Timestamp : DateTime;
Open : string; High : string; Low : string; Close : string;
Volume: int;
}
// F.US.DGH12 20111201 0107 110020 110020 110020 110020 1
let parse_bar (line : string, delim : char) =
@DexterHaslem
DexterHaslem / gist:2648306
Created May 9, 2012
depth first search (kill ur stack)
View gist:2648306
public static IEnumerable<T> DepthFirstSearch<T>(IEnumerable<T> start, Func<T, IEnumerable<T>> selector, Func<T, bool> predicate)
{
var results = new List<T>();
foreach (T item in start)
{
if (predicate != null && predicate(item))
results.Add(item);
else if (predicate == null)
results.Add(item);
var subItems = selector(item);
View gist:2662834
public static IEnumerable<T> FlattenTree<T>(IEnumerable<T> list, Func<T, IEnumerable<T>> subitems)
{
foreach (T child in list)
{
yield return child;
foreach (T other in FlattenTree(subitems(child), subitems))
yield return other;
}
}
View gist:3041454
protected override void OnBarUpdate()
{
if (Historical) return;Enumerable.Range(0,14).ToList().ForEach(i =>DrawText((CurrentBar+i).ToString(),"\u0CA0_\u0CA0",0, i % 2 == 0 ? (Close[0]+TickSize) + (TickSize*i) : (Close[0]-TickSize)-(TickSize*i),i % 2 == 0 ? Color.FromArgb(255 - (i*15),0, 0,255):Color.FromArgb(255 - (i*15),255, 0,0)));
}
View gist:3084661
protected override void OnBarUpdate()
{
string indicator = "EMA";
Type indicatorType = Type.GetType("NinjaTrader.Indicator." + indicator);
IndicatorBase indicatorBase = (IndicatorBase) Activator.CreateInstance(indicatorType);
Print(indicatorBase.GetHashCode() + ":" + indicatorBase.GetType().FullName);
indicatorBase.BarsRequired = BarsRequired;
indicatorBase.CalculateOnBarClose = CalculateOnBarClose;
indicatorBase.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicatorBase.MaximumBarsLookBack = MaximumBarsLookBack;
@DexterHaslem
DexterHaslem / gist:3085590
Created Jul 10, 2012
NinjaTrader create Indicator type @ runtime
View gist:3085590
using System;
using System.ComponentModel;
namespace NinjaTrader.Indicator
{
[Description("f")]
public class derp : Indicator
{
IndicatorBase myEMA;
protected override void Initialize()
You can’t perform that action at this time.