Wikipedysta:Kskowron/Programowanie
SDL pod Dev-Cpp
Project -> Project Options -> Parameters -> Linker:
Koniecznie w tej kolejności (inaczej się nie zlinkuje): -lmingw32 -lSDLmain -lSDL Można dodać: -lopengl32 -lglu32"
trzeba jeszcze pamiętać, żeby był dostępny SDL.dll i liby i includy.
UWAGA: main musi mieć nagłówek "int main( int, char*[] )", inaczej się nie zlinkuje.
Init SDL
int main( int argc, char* argv[] )
{
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 0, SDL_OPENGL );
SDL_Quit();
return EXIT_SUCCESS;
}
Init GL
glClearColor( 0.5,0.5,0.5,0 );
glViewport( 0, 0, 640, 480 );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 70, 640./480., 1, 100 );
glShadeModel( GL_SMOOTH );
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_COLOR_MATERIAL );
glEnable( GL_LIGHT0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
while( true )
{
glPushMatrix();
glTranslatef( 0, 0, -odl );
glRotatef( theta, 1, 0, 0 );
glRotatef( fi, 0, 1, 0 );
float lightpos[] = { 2, 2, 2, 0 };
glLightfv( GL_LIGHT0, GL_POSITION, lightpos );
glColor3f( 1, 0, 0 );
...
SDL_GL_SwapBuffers();
}
SDL Events
SDL_Event event;
while( SDL_PollEvent( &event ) )
switch( event.type )
{
case SDL_MOUSEMOTION:
if( event.motion.state & SDL_BUTTON(1) )
{
fi += event.motion.xrel;
theta += event.motion.yrel;
}
if( event.motion.state & SDL_BUTTON(3) )
{
odl += event.motion.yrel*0.1;
}
break;
case SDL_KEYDOWN:
case SDL_QUIT:
goto quit;
}
SDL Pixels
SDL_Init( SDL_INIT_VIDEO );
screen = SDL_SetVideoMode( 500, 500, 0, 0 );
SDL_LockSurface( screen );
...
SDL_UnlockSurface( screen );
SDL_UpdateRect( screen, 0, 0, 0, 0 );
SDL_Quit();
void PutPixel( int x, int y, Uint32 col = color )
{
if( x >= 0 && x < screen->w && y >= 0 && y < screen->h )
((Uint32*)screen->pixels)[ screen->w * y + x ] = color;
}
void ClearScreen( Uint32 col = color )
{
SDL_FillRect( screen, NULL, color );
}
void SetColor( double r, double g, double b )
{
color = SDL_MapRGB( screen->format, (int)(r*255),(int)(g*255),(int)(b*255) );
}
void PutPoint( double x, double y )
{
int xp = (int)(scale*x*screen->w) + centerx;
int yp = (int)(scale*(-y)*screen->h) + centery;
PutPixel( xp, yp );
}
XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript">
//<![CDATA[
//]]>
</script>
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="stylesheet" href="https://profillengkap.com/pl/style.css" type="text/css" />
</head>
<body>
<div id="main"></div>
</body>
</html>
CSS
<style type="text/css">
p { color: red }
</style>
div centered on a page:
div.centered {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 60%;
height: 60%;
margin: auto;
background-color: red;
color: white;
}
Text horizontal and vertical centering in a div:
div.centering {
width: 60px;
height: 60px;
display: table-cell;
vertical-align: middle;
text-align: center;
background-color: red;
}
Horizon:
div.horizon {
position: relative;
top: 50%;
height: 1px;
width: 100%;
overflow: visible;
background-color: blue;
}
Robots
<meta name="robots" content="noindex, nofollow"/>
JavaScript
Authors should specify the default scripting language for all scripts in a document:
Content-Script-Type: application/javascript or <meta http-equiv="Content-Script-Type" content="application/javascript">
The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading.
There is also DOMContentLoaded event (which can be handled using addEventListener) which is fired after the DOM for the page has been constructed, but doesn't wait for other resources to finish loading.
window.onload = func;
AJAX
function MakeRequest( url, text )
{
var request = new XMLHttpRequest();
request.onreadystatechange = function() { StateChanged(request); };
request.open( "POST", url, true );
//żeby serwer nie odrzucał POSTa
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//żeby przeglądarka nie zakeszowała
request.setRequestHeader('Cache-Control', 'no-cache');
request.send( text );
}
function StateChanged( request )
{
if( request.readyState == 4 )
{
if( request.status == 200 )
writetext( mainbox, request.responseText );
else
writetext( logbox, "request failed: " + request.status + " " + request.statusText + "\n");
}
}
MakeRequest( "./example.php", "text="+ encodeURIComponent( input.value + "\n" ) );
PHP
.htaccess
php_value upload_max_filesize 20M php_value post_max_size 20M php_value memory_limit 100M php_value max_execution_time 60 php_value max_input_time 60 //na requesta od klienta (np. upload zdjęcia) w sekundach
Redirect
header("Location: http://skowron.no-ip.org/kuba/");
http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php
Terminal
np. "\e[10;10H". Specjalne sa tez dla m.in. xterma do wczytywania rozmiaru (rows, cols).
Klawiatura
Wylaczenie echa (zeby nie wypisywal na ekran tego co piszesz na klawiaturze) i trybu kanonicznego (m.in. zeby nie buforowal, czekajac na enter): wyzerowac flagi ECHO i ICANON.
man termios tcgetaddr tcsetaddr
termios termios_saved,aTermios;
if( tcgetattr( stdin_fd, &termios_saved ) == -1 )
perror("get termios");
aTermios = termios_saved;
aTermios.c_lflag &= ~(ECHO | ICANON );
// aTermios.c_iflag &= ~(ISTRIP | INLCR | ICRNL | IGNCR | IXON | IXOFF);
// aTermios.c_lflag &= ~(ECHO | ISIG | ICANON);
if( tcsetattr( stdin_fd, TCSANOW, &termios_set) == -1 )
perror("set termios");
...
if( tcsetattr( stdin_fd, TCSANOW, &termios_saved ) == -1 )
perror("restore termios");
(do tego moznaby uzyc ioctl z argumentem TCGETS i TCSETSW, ale to jest nie portable, lepiej uzywac tych posiksowych)
Klawiatura RAW
(tylko na fizycznym terminalu, nie przez xterma ani zdalnie) Tryb K_RAW (czyli dostajemy keydowny i keyupy razem ze scan codami klawiszy na wejsciu ). ioctl z argumentem KDGKBMODE wczytuje aktualny stan, a z argumentem KDSKBMODE ustawiamy tryb K_RAW.
Uwaga! koniecznie trzeba przed wyjsciem przywrocic poprzedni stan klawiatury, bo inaczej zablokujesz terminal na twardo.
man ioctl man ioctl_list
long int kbmode_saved,kbmode;
if( ioctl( stdin_fd, KDGKBMODE, &kbmode_saved ) == -1 )
perror("get kbmode");
kbmode = K_RAW;
if( ioctl( stdin_fd, KDSKBMODE, kbmode ) == -1 )
perror("set kbmode");
...
if( ioctl( stdin_fd, KDSKBMODE, kbmode_saved ) == -1 )
perror("restore kbmode");
for (( a=1; a <= 10; a++ )); do convert file_$a.png file_$a.ps; done; psmerge -ofile.ps $( for((a=1; a<=10; a++)); do echo file_$a.ps; done; )
Creating lossless PDF
ps2pdf -dUseFlateCompression=true -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode
For grayscale images use "Gray" instead "Color". Więcej http://skowron.no-ip.org/kuba/public/Tworzenie%20dokument%C3%B3w%20pdf%20przy%20pomocy%20LATEX-a.pdf
To be able to finely control the compression of the images:
cat ABC.ps | gs -sDEVICE=pdfwrite -sOutputFile=ABC.pdf -dAutoFilterColorImages=false -c "<< /ColorImageDict << /QFactor 0.1 /Blend 1 /HSample [1 1 1 1] /VSample [1 1 1 1] >> >> setdistillerparams" -
Adjusting the QFactor away from 0.1 adjusts the quality of compression, but I don't know what range of values it can take (although 0.9 is default)
mencoder
Encoding from multiple input image files
mencoder mf://@list -o out.avi -ovc copy
convert
convert "file" -geometry '600x600>' "small_file"
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.