Skip to content

Instantly share code, notes, and snippets.

@follesoe
Last active February 11, 2016 09:32
Show Gist options
  • Save follesoe/26f08637b8d806bbac2e to your computer and use it in GitHub Desktop.
Save follesoe/26f08637b8d806bbac2e to your computer and use it in GitHub Desktop.
Forslag til kildekode på folie på glassvegg
(define factorial
(lambda (n)
(if (= n 0)
1
(* n (factorial (- n 1))))))
*-------------------------------
*
* Draw entire 10 x 3 screen from scratch
*
*-------------------------------
SURE
lda #1
sta genCLS ;clear screen
jsr setback ;draw on bg plane
jsr getprev ;get 3 rightmost blocks of screen to left
lda SCRNUM
jsr calcblue ;get blueprint base addr
/*--------------------------------------------------------
HELLOWIN.C -- Displays "Hello, Windows" in client area
(c) Charles Petzold, 1990
--------------------------------------------------------*/
#include <windows.h>
long FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
static char szAppName[] = "HelloWin" ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
RegisterClass (&wndclass) ;
}
hwnd = CreateWindow (szAppName, // window class name
"The Hello Program", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, "Hello, Windows!", -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Aside from the antique C syntax and the weird idiosyncratic formatting, I think most people would agree that compared with Microsoft's original, mine is a model of clarity and brevity.
Eventually I got tired of people complaining how long my "Hello World" program was, so Programming Windows, 5th edition (1998) began with this program:
/*--------------------------------------------------------------
HelloMsg.c -- Displays "Hello, Windows 98!" in a message box
(c) Charles Petzold, 1998
--------------------------------------------------------------*/
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT ("HelloMsg"), 0) ;
return 0 ;
}
#************************************************************************
# ENTRY POINTS: ?GUIDSUB FOR THE IGNITION ALGORITHM, LUNLAND FOR SERVOUT
#************************************************************************
# IGNITION ALGORITHM ENTRY: DELIVERS N PASSES OF QUADRATIC GUIDANCE
?GUIDSUB EXIT
CAF TWO # N = 3
TS NGUIDSUB
TCF GUILDRET +2
GUIDSUB TS NGUIDSUB # ON SUCCEEDING PASSES SKIP TTFINCR
TCF CALCRGVG
# NORMAL ENTRY: CONTROL COMES HERE FROM SERVOUT
LUNLAND TC PHASCHNG
OCT 00035 # GROUP 5: RETAIN ONLY PIPA TASK
TC PHASCHNG
OCT 05023 # GROUP 3: PROTECT GUIDANCE WITH PRIO 21
OCT 21000 # JUST HIGHER THAN SERVICER'S PRIORITY
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
return y;
}
@kristoffer-dyrkorn
Copy link

FFT:

def fft(x):
    N = len(x)
    if N <= 1: return x
    even = fft(x[0::2])
    odd =  fft(x[1::2])
    T= [exp(-2j*pi*k/N)*odd[k] for k in range(N//2)]
    return [even[k] + T[k] for k in range(N//2)] + [even[k] - T[k] for k in range(N//2)]

@trondkla
Copy link

Robert'); DROP TABLE students; --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment