Skip to content

Instantly share code, notes, and snippets.

Parent-window.html
this.$el.append('<iframe id="iframeDocument" src="/Iframe.html"></iframe>');
loadIframe = function() {
var $iframeDocument = $('#iframeDocument').get(0).contentWindow.document;
$('#iframeContent', $iframeDocument).append( myHtml );
}
@lydonchandra
lydonchandra / gist:5675402
Created May 30, 2013 02:28
Mocking/Spoofing Browser Geolocation W3C API Call GpsMock.mock() to mock/spoof
var GpsMock = {
mockSetIntervalId : null,
mock : function( x, y ) {
var setIntervalId;
if( navigator.geolocation ) {
var self = this;
if( !x ) {
//start x y not set, try to get 'REAL' current location and use it
navigator.geolocation.getCurrentPosition(
function success(position) { self.mock(position.coords.longitude, position.coords.latitude) },
@lydonchandra
lydonchandra / gist:7981296
Created December 16, 2013 01:56
send XML string as POST body into WCF endpoint
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/proxy/?url={url}")]
String proxy_GET(string url);
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "/proxy/?url={url}")]
XElement proxy_POST(string url, XElement postData);
//const __m128 half = _mm_set1_ps(0.5f);
//set our packed floats to 1.5f
__m256 half256ps = _mm256_set1_ps(1.5f);
//make room for our 256bits result variable
__m256i result256i;
unsigned X, X0, X1, X2, X3, X4, X5, X6, X7;
@lydonchandra
lydonchandra / imul-or-leaq.cs
Last active January 1, 2016 01:49
Use LEA as a faster way to do multiplication
//rax = 450 * rbx
imulq $450, %rbx, %rax ## imm = 0x1C2
//another way to do rax = 450 * rbx
//cycle wise, this is on par with imul instruction above
leaq (%rbx,%rbx,8), %rax //rax=9*rbx
leaq (%rax,%rax,4), %rax //rax=rax*5 == 45*rbx
leaq (%rax,%rax,4), %rax //rax=rax*5 == 225*rbx
shlq $1,%rax //rax=rax*2 == 450*rbx
@lydonchandra
lydonchandra / parameter passing amd64bin gcc osx.cs
Last active January 1, 2016 05:59
parameter passing amd64bin gcc osx
__m128 __attribute__ ((noinline)) test_parameterPassing(
__m128 m128param1, //%xmm0
unsigned u1, //%edi
float f1, float f2, //%xmm1, %xmm2
unsigned u2, unsigned u3, //%esi, %edx
double d1, double d2, //%xmm3, %xmm4
unsigned u4, unsigned u5, //%ecx, %r8d
double d3, double d4, double d5, double d6, //%xmm5, %xmm6, %xmm7, stack
unsigned u6, unsigned u7, unsigned u8 //%r9d, stack, stack
) {
@lydonchandra
lydonchandra / vpshufd-example.cs
Last active November 23, 2024 01:05
How to use pshufd instruction (pack shuffle) //0x00 set all elems to 1st elem, 0000 0000 //0x55 set all elems to 2nd elem, 0101 0101 //0xAA set all elems to 3rd elem, 1010 1010 //0xFF set all elems to 4th elem, 1111 1111 //0x1B reverse order, 0001 1011
printf("m128i.m128_u32[0] = %04X _ before\n", m128i.m128_u32[0]);
printf("m128i.m128_u32[1] = %04X _ before\n", m128i.m128_u32[1]);
printf("m128i.m128_u32[2] = %04X _ before\n", m128i.m128_u32[2]);
printf("m128i.m128_u32[3] = %04X _ before\n", m128i.m128_u32[3]);
__asm {
pxor xmm5, xmm5
//vpshufd xmm5, m128i, 0xAA
vpshufd xmm5, m128i, 0x55
//0x00 set all elems to 1st elem, 0000 0000
@lydonchandra
lydonchandra / parameter passing pointer and __m256.cpp
Last active January 1, 2016 08:29
parameter passing pointer and __m256
void test_parameterPassing_pointer( double *d1p,
__m256 *m256_1p, __m128 *m128_1p,
__m256 m256_1) {
double mul1 = (*d1p) + (*d1p);
double *m256_dp = ((double*)m256_1p);
double *m128_dp = ((double*)m128_1p);
double mul2 = m256_dp[0] * mul1 - m128_dp[1];
@lydonchandra
lydonchandra / test_vinsertps.cpp
Last active January 1, 2016 08:58
test_vinsertps.cpp
void test_vinsertps() {
__m128i m128_1;
unsigned long long allOneLL = 0x2222222211111111LL;
unsigned long long allTwoLL = 0x4444444433333333LL;
((unsigned long long*)&m128_1)[0] = allOneLL;
((unsigned long long*)&m128_1)[1] = allTwoLL;
@lydonchandra
lydonchandra / test_unpckldq.cpp
Last active January 1, 2016 13:09
test_unpckldq and unpcklqdq
void test_punpckldq() {
__m128i m128_1;
__asm {
mov r8d, 0x11112222
mov r9d, 0x33334444
mov r10d,0x55556666
mov r11d,0x77778888
movd xmm8, r8d