Skip to content

Instantly share code, notes, and snippets.

static __inline void do_cpuid(u_int ax, u_int *p) {
__asm __volatile("pushl %%ebx\n\t"
"cpuid\n\t"
"movl %%ebx, %%esi\n\t"
"popl %%ebx\n\t"
: "=a" (p[0]), "=r" (p[1]), "=c" (p[2]), "=d" (p[3])
: "a" (ax));
}
<?php
class DatabaseStatementBase extends PDOStatement {
public $dbh;
protected function __construct($dbh) {
$this->dbh = $dbh;
$this->setFetchMode(PDO::FETCH_OBJ);
}
}
<?php
class DatabaseStatementBase extends PDOStatement {
public $dbh;
protected function __construct($dbh) {
$this->dbh = $dbh;
$this->setFetchMode(PDO::FETCH_OBJ);
}
public function fetchAllKeyed($key_index = 0, $value_index = 1) {
<?php
function saveCacheFile($file, $contents)
{
$serialized = serialize($contents);
$len = strlen($serialized);
$cachefile_fp = @fopen($file, 'xb'); // x is the O_CREAT|O_EXCL mode
if ($cachefile_fp !== false) { // create file
if (fwrite($cachefile_fp, $serialized, $len) < $len) {
return PEAR::raiseError("Could not write $file.");
@scottmac
scottmac / elastic search query
Created March 2, 2011 23:48
{"error":"ArrayIndexOutOfBoundsException[null]","status":500}
curl -XPUT 'http://127.0.0.1:9200/test/post/2569686' -d '
{"node":32,"thread":91521,"title":"Allies in Blood \"A Universe of Change-Part 3\"","message":"\u201cGreetings Captain, Data, and young Crusher,\u201d Draal said in his less than normally booming voice. \u201cYou are no doubt aware of what is happening on Minbar.\u201d At this Picard\u2019s face darkened. \u201cYes,\u201d he whispered, \u201cI know about your probes.\u201d He waved off the looks of concern. \u201cI can hardly fault you since I have been doing the same thing,\u201d he said conspiratorially. \u201cMy people don\u2019t know and if they did right now they should bless you considering the situation. But I am getting away from purpose of you being here. Captain, without a living controller, the Great Machine will destroy itself in four days. My doctors, captors that they are, will not free me from this prison until I am well enough and the last time a controller was lost, war almost broke out. Commander Sheridan and Delenn, I beli
<?php
$a = 1;
if ($a == ++$a) {
echo "they're equal? WTF??", PHP_EOL;
}
@scottmac
scottmac / gist:1095554
Created July 20, 2011 18:22
OpenSSL Patch for Windows
diff --git a/crypto/rand/rand_win.c b/crypto/rand/rand_win.c
index 5d134e1..d74fa43 100644
--- a/crypto/rand/rand_win.c
+++ b/crypto/rand/rand_win.c
@@ -383,6 +383,11 @@ int RAND_poll(void)
if (advapi)
FreeLibrary(advapi);
+ /* If good then the Windows Crypto API worked, this does
+ the same as below so skip duplicating work */
@scottmac
scottmac / serial.cpp
Created September 16, 2011 07:17
Find serial number of USB device on OS X.
#include <stdio.h>
#include <stdlib.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/usb/IOUSBLib.h>
#include <IOKit/hid/IOHIDKeys.h>
CFStringRef find_serial(int idVendor, int idProduct) {
CFMutableDictionaryRef matchingDictionary = IOServiceMatching(kIOUSBDeviceClassName);
import java.util.List;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.nio.ByteBuffer;
import javax.smartcardio.*;
class ProxNRollReader {
byte[] GET_UID = {(byte)0xFF, (byte)0xCA, (byte)0x00,
(byte)0x00, (byte)0x00};
CONNECTED(00000003)
depth=2 /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA
verify return:1
depth=1 /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance CA-3
verify return:1
depth=0 /C=US/ST=California/L=San Francisco/O=Milk Inc./OU=Oink/CN=*.oink.com
verify return:1