Skip to content

Instantly share code, notes, and snippets.

@a3f
a3f / DoS.S
Last active October 16, 2016 21:33
DoS patch
<00603F80>
@_check_hwdebug:
push ebp
mov ebp, esp
push esi
push ebx
sub esp, 16
mov eax, DWORD PTR [ebp+12]
mov ebx, DWORD PTR [ebp+8]
mov DWORD PTR [esp+4], eax
@a3f
a3f / bindPastePlayingTrack.ahk
Last active August 16, 2016 09:30
print a user's playing track on last.fm (or Spotify if last.fm is connected)
apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
secret = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
user = xxx
^F3::
{
dhw := A_DetectHiddenWindows
DetectHiddenWindows On
Run "%ComSpec%" /k,, Hide, pid
while !(hConsole := WinExist("ahk_pid" pid))
Sleep 10
@a3f
a3f / cvar.c
Last active July 6, 2016 04:44
Condition variable spurious wakeup example
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/param.h>
#ifdef BSD
#define INTERRUPT_CVAR SIGINFO
#else
#define INTERRUPT_CVAR SIGUSR1
#endif
@a3f
a3f / transpose.cc
Last active February 28, 2016 15:11
// http://stackoverflow.com/questions/11413855/why-is-transposing-a-matrix-of-512x512-much-slower-than-transposing-a-matrix-of
#define SAMPLES 100
#ifndef MATSIZE
#define MATSIZE 512
#endif
#include <ctime>
#include <iostream>
int mat[MATSIZE][MATSIZE];
@a3f
a3f / trial-division.c
Last active August 16, 2016 11:44
quick example of using MPI to parallelise trial division primality checking
#include <mpi.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef unsigned long long ull;
// all communication is either input to workers or output from workers
enum {TAG_INPUT = 2001, TAG_RESULT};
#include <stdio.h>
typedef int (*two_var_func) (int, int);
typedef int (*one_var_func) (int);
int add_int (int a, int b) {
return a+b;
}
#define partial(f, a) ({ \
/**
* argv[1]="769" doesn't work (with #define BUF_LEN 8)
* Environment: Windows 10 x86_64 with ../../../src/gcc-4.9.2/configure --host=i686-w64-mingw32
*
* Classical undefined behavior: recv's buffer is shorter than the buffer length supplied
* But not all wrong buffers are equal, when buf_len >= 769, the recv fails immediately,
* with no error code set, which is strange because there has been nothing recieved, so a wrong
* buffer length shouldn't have mattered right?
* If buf_len < 769 the code does what one would assume, blocking wai for a UDP packet
*/
#include <windows.h>
HWND hwnd;
LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t * lpCmdLine, int nCmdShow)
{
MSG Msg;
WNDCLASSEX WndClsEx = {0};
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
#include <complex.h>
#include <math.h>
const char *title = "Mandelbrot Set";
#define SIZE 600
#define ITERS 25
int main(void)
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
char *title = "Mandelbrot Set";
#define SIZE 600
#define ITERS 25
int main()
{
int x, y, i;
double zx, zy, cx, cy, tmp;