Skip to content

Instantly share code, notes, and snippets.

🤙
Being awesome

Rob Janssen RobThree

🤙
Being awesome
View GitHub Profile
@RobThree
RobThree / SoapClientTimeout.class.php
Created Apr 25, 2012
PHP SoapClient with timeout
View SoapClientTimeout.class.php
<?php
//Drop-in replacement for PHP's SoapClient class supporting connect and response/transfer timeout
//Usage: Exactly as PHP's SoapClient class, except that 3 new options are available:
// timeout The response/transfer timeout in milliseconds; 0 == default SoapClient / CURL timeout
// connecttimeout The connection timeout; 0 == default SoapClient / CURL timeout
// sslverifypeer FALSE to stop SoapClient from verifying the peer's certificate
class SoapClientTimeout extends SoapClient
{
private $timeout = 0;
private $connecttimeout = 0;
@RobThree
RobThree / wavefilereader.class.php
Created Aug 29, 2012
PHP WAVE file reader / parser
View wavefilereader.class.php
<?php
/**
* WaveFileReader; a simple class to read/parse WAVE file
* (c)2012 Rob Janssen / https://github.com/RobThree
*
* Based on https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
*
* USAGE:
*
* $wav = WaveFileReader::ReadFile('/path/to/test.wav');
View hotlinkchecker.class.php
<?php
/*
* Class for checking if images are hotlink-protected
*/
class HotlinkChecker {
// You can set this property to any random domain; this will be sent
// as the referring domain to check the "hotlink protected" version
public $testhost = 'www.somerandomdomain.com';
// You can change (or add/remove) any cURL options through this property
@RobThree
RobThree / SoapClientEx.class.php
Created Nov 20, 2012
PHP SoapClient with timeout and authentication
View SoapClientEx.class.php
<?php
//**NOTE**: This has *NOT* been tested yet; please provide feedback in the comments
//Drop-in replacement for PHP's SoapClient class supporting connect and response/transfer timeout and authentication
//Usage: Exactly as PHP's SoapClient class, except that some new options are available:
// timeout The response/transfer timeout in milliseconds; 0 == default SoapClient / CURL timeout
// connecttimeout The connection timeout; 0 == default SoapClient / CURL timeout
// sslverifypeer FALSE to stop SoapClient from verifying the peer's certificate
// sslversion The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually
// sslverifyhost 1 to check the existence of a common name in the SSL peer certificate. 2 to check the existence of a common name and also verify that
@RobThree
RobThree / TextSelectionReader.cs
Last active Apr 23, 2020
Class that can be used to retrieve the currently selected text (if any) from an active control in the active window. It does this by trying several methods internally (UIAutomation, API calls using SendMessage + WM_GETTEXT, Clipboard). Be sure to reference UIAutomationClient and UIAutomationTypes!
View TextSelectionReader.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Automation;
using System.Windows.Forms;
//WARNING: The code below is NOT for the faint of heart. Exceptions are swallowed freely, sendkeys
@RobThree
RobThree / PhonenumberGrabber.cs
Last active Dec 13, 2015
Tries to grab phonenumbers from an active control (selected text) in an active window. Uses a TextSelectionReader internally (see https://gist.github.com/RobThree/4943725).
View PhonenumberGrabber.cs
using System;
using System.Linq;
using System.Text.RegularExpressions;
/// <summary>
/// Tries to grab phonenumbers from an active control (selected text) in an active window. Uses
/// a <see cref="TextSelectionReader"/> internally.
/// </summary>
public class PhonenumberGrabber
{
@RobThree
RobThree / linqhelpers.cs
Last active Dec 21, 2015
Linq extensions: Diff, ToChunks and ExecuteChunked
View linqhelpers.cs
using System;
using System.Linq;
using System.Collections.Generic;
//Sample program demonstrating the linq extensions (below Progam class)
class Program
{
static void Main(string[] args)
{
//Demonstrate Diff
View whitespacewatermarker.cs
using System;
using System.Linq;
using System.Text;
//Demonstrate usage
class Program
{
static void Main(string[] args)
{
var ww = new WhitespaceWatermarker();
@RobThree
RobThree / exampleclassesandinterfaces.cs
Created Nov 1, 2013
An improvement upon http://stackoverflow.com/a/4100126/215042. This factory can be used as a generic factory. Improvements are, amongst others: • Generics • Being able to specify case(in)senstivity when resolving instances • Constructor overloads; the default will assume the Executing Assembly, other assemblies can be passed using an overload of…
View exampleclassesandinterfaces.cs
public interface IFood
{
bool IsTasty { get; }
}
public class Hamburger : IFood
{
public bool IsTasty { get { return true; } }
}
@RobThree
RobThree / ratelimiter.php
Last active Dec 16, 2019
Simple, rude, rate limiter (using memcache).
View ratelimiter.php
<?php
/* Very simple, crude, rate limiter */
/*
Assumes _MEMCACHEDSITEPREFIX, _MEMCACHEDHOST and _MEMCACHEDPORT are `defined`:
define('_MEMCACHEDHOST', '127.0.0.1');
define('_MEMCACHEDPORT', 11211);
define('_MEMCACHEDSITEPREFIX', 'mysite');
*/
You can’t perform that action at this time.