Skip to content

Instantly share code, notes, and snippets.

View meklarian's full-sized avatar

Paul Shinn meklarian

View GitHub Profile
@meklarian
meklarian / InProcessThreadShareTest.cpp
Created October 28, 2009 02:08
Src for a win32 console program that demonstrates cross-thread shared file access.
// InProcessThreadShareTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
void EmitError(DWORD dwErr)
{
if(dwErr != 0)
{
@meklarian
meklarian / SharedFileClient.cpp
Created October 28, 2009 02:10
Src for a pair of win32 console programs to demonstrate cross-process file access.
// SharedFileClient.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <time.h>
void EmitError(DWORD dwErr)
{
if(dwErr != 0)
@meklarian
meklarian / UCS2Encode.php
Created January 5, 2010 15:01
Source code examples of hex encodings for various Unicode formats, with verified Arabic support.
<?php
// REF: Source code corresponding to http://stackoverflow.com/questions/1872773/ucs2-hexencoded-characters
header('Content-Type: text/html; charset=UCS-2');
mb_http_output('UCS-2');
echo mb_convert_encoding('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UCS-2" /></head><body>', 'UCS-2', 'auto');
echo mb_convert_encoding('encoding: ', 'UCS-2', 'auto');
echo mb_convert_encoding(mb_http_output(), 'UCS-2', 'auto');
echo mb_convert_encoding('<br />', 'UCS-2', 'auto');
// NOTE: Replace the string here with your phrase
$strTerm = '!مرحبا عالم';
@meklarian
meklarian / UCS2HexToUTF8.php
Created January 5, 2010 17:23
Reverse mapping of prior gist, Hex-string representation of UCS-2 into UTF-8 native string, with verified Arabic support.
<?php
// REF: Source code corresponding to http://stackoverflow.com/questions/2005358/ucs2-hexencoded-characters-to-utf8-in-php
function local_hex2bin($h)
{
if (!is_string($h)) return null;
$r='';
for ($a=0; $a<strlen($h); $a+=2) { $r.=chr(hexdec($h{$a}.$h{($a+1)})); }
return $r;
};
@meklarian
meklarian / bookmarklet.html
Created April 30, 2010 21:48
javascript src file used in bookmarklet to expand images & video on twitter & favstar.fm
<a href="javascript:(function(){var ssl=('https:'==document.location.protocol);if(ssl){return;};var e=document.createElement('script');e.src='http://www.meklarian.com/mekfavelet/picture-previews3.js';document.getElementsByTagName('head')[0].appendChild(e);})();">Previews v4</a>
@meklarian
meklarian / AutoTimer.cs
Created May 6, 2010 09:54
quick and dirty auto-disposing timer that can be used to measure times for blocks of code by gaming the using() statement
using System.Diagnostics;
namespace YourFavoriteNamespace
{
public class AutoTimer : IDisposable
{
public AutoTimer()
{
_Init();
}
@meklarian
meklarian / DJ2RSS.ashx.cs
Created May 8, 2010 10:56
ASP.NET generic handler that converts a blip.fm user's recent blips into RSS 2.0 format, suitable for embedding on flavors.me [.NET 2.0 compatible!]
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
@meklarian
meklarian / MainWindow.xaml
Created May 16, 2010 22:44
source code demonstrating correct image size lookup for an asynchronous image in WPF
<Window x:Class="ImageLookup.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
@meklarian
meklarian / PZIAdapter.cpp
Created May 26, 2010 09:59
Source code for a Win32 DLL and a sample C# project demonstrating a single function that can be used to scrub out Persistent-Zone-Identifiers (PZIs) from files.
// PZIAdapter.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "PZIAdapter.h"
// This is an example of an exported function.
PZIADAPTER_API DWORD _stdcall StripFilePZI(BSTR bstrFilename)
{
if(!bstrFilename){return E_INVALIDARG;}
// HelperDlg.cpp : implementation file
//
#include "stdafx.h"
// NOTE: CWinApp Include goes here instead of WindowBits2.h
#include "WindowBits2.h"
#include "HelperDlg.h"
// NOTE: Not all versions of MFC have "afxdialogex.h" this present
#include "afxdialogex.h"