Skip to content

Instantly share code, notes, and snippets.

@rdp
rdp / send_ctrl_c.c
Last active December 20, 2023 08:02
// attribution: http://stackoverflow.com/a/15281070/32453
// you can compile this with gcc [mingw or mingw-w64] and probably other compilers as well
#include <stdlib.h> // NULL
#include <stdbool.h> // false
#include <windows.h> // AttachConsole, CTRL_C_EVENT, etc.
#include <stdio.h> // printf
#include <strsafe.h>
void logLastError()
@rdp
rdp / crc32er.rb
Last active November 6, 2023 17:51
crc32c for ruby
require 'digest/crc32c' # gem install digest-crc
p 'syntax: something to get digested! [output it with trailing 4 byte digest, in ruby string syntax]'
checksum = Digest::CRC32c.checksum(ARGV[0])
p checksum
out = ARGV[0].dup.bytes # assume it starts ascii :|
for n in [24, 16, 8, 0]
next_byte = (checksum >> n & 0xff)
out << next_byte
p "x%x" % next_byte
end
package main
// doesn't work, unfortunately :|
// #include <windows.h>
// #include <psapi.h>
import "C"
import "unsafe"
import "fmt"
import "syscall"
@rdp
rdp / out.log
Created October 17, 2017 03:36
chrome playing success embedded <html> <video> tag
10-16 20:36:04.927 4174-4201/com.android.chrome:privileged_process0 D/EGL_emulation: eglMakeCurrent: 0x91690820: ver 2 0 (tinfo 0xafb83b80)
10-16 20:36:04.932 4174-4201/com.android.chrome:privileged_process0 D/EGL_emulation: eglMakeCurrent: 0x90b85f40: ver 2 0 (tinfo 0xafb83b80)
10-16 20:36:04.947 4174-4201/com.android.chrome:privileged_process0 D/EGL_emulation: eglMakeCurrent: 0x90b83000: ver 2 0 (tinfo 0xafb83b80)
10-16 20:36:04.948 4174-4201/com.android.chrome:privileged_process0 D/EGL_emulation: eglMakeCurrent: 0x90b85f40: ver 2 0 (tinfo 0xafb83b80)
10-16 20:36:04.951 4174-4201/com.android.chrome:privileged_process0 D/EGL_emulation: eglMakeCurrent: 0x90b83000: ver 2 0 (tinfo 0xafb83b80)
10-16 20:36:04.952 4174-4201/com.android.chrome:privileged_process0 D/EGL_emulation: eglMakeCurrent: 0x90b85f40: ver 2 0 (tinfo 0xafb83b80)
10-16 20:36:04.962 4174-4201/com.android.chrome:privileged_process0 D/EGL_emulation: eglMakeCurrent: 0x91690820: ver 2 0 (tinfo 0xafb83b80)
10-16 20:36:04.964 4174-4201/com.android.chr
// enum.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdio>
#include <cstring>
#include <windows.h>
#include <comcat.h>
int rcvBufferSize;
int sockOptSize = sizeof(rcvBufferSize);
getsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &rcvBufferSize, &sockOptSize);
printf("initial socket receive buf %d\n", rcvBufferSize);
@rdp
rdp / create.cr
Created April 14, 2023 04:57
create EIA 608 byte pairs
to_encode = "abcdABCD"
outy = Array(UInt8).new
to_encode.each_char{|c|
if c.in_set?("A-Z")
outy << 0x41_u8 + (c - 'A') # https://en.wikipedia.org/wiki/EIA-608#Characters
elsif c.in_set?("a-z")
outy << 0x61_u8 + (c - 'a')
else
raise "don't translate more chars yet"
end
@rdp
rdp / gist:1894747
Created February 23, 2012 19:58
rake --trace
ruby -vS rake build --trace
ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
(in c:/dev/ruby/sane)
C:/installs/Ruby192/lib/ruby/gems/1.9.1/gems/jeweler-1.5.2/lib/jeweler/tasks.rb:46: warning: method redefined; discarding old jeweler
C:/installs/Ruby192/lib/ruby/gems/1.9.1/gems/jeweler-1.5.2/lib/jeweler/specification.rb:110: warning: method redefined; discarding old initialize_copy
C:/installs/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1352: warning: previous definition of initialize_copy was here
** Invoke build (first_time)
** Execute build
C:/installs/Ruby192/lib/ruby/gems/1.9.1/gems/jeweler-1.5.2/lib/jeweler/tasks.rb:47: warning: instance variable @jeweler not initialized
C:/installs/Ruby192/lib/ruby/gems/1.9.1/gems/git-1.2.5/lib/git/object.rb:25: warning: method redefined; discarding old size
@rdp
rdp / gist:1153062
Created August 18, 2011 01:13
example use of QueryPerformanceCounter
long double PCFreqMillis = 0.0;
// this call only needed once...
// who knows if this is useful or not, speed-wise...
void WarmupCounter()
{
LARGE_INTEGER li;
BOOL ret = QueryPerformanceFrequency(&li);
assert(ret != 0); // only gets run in debug mode LODO
require "benchmark"
require "uuid"
Benchmark.ips do |x|
x.report { UUID.random }
end