Posts by admin

What is npviewer.bin? Why it takes all computer's power?

- by admin

This is a Netscape plugin viewer.

It is used, most of the time, to play some Flash animations in Firefox. These are unsuseful commercial ads very often.

PHP Get File Extension

- by admin

Just some examples:
$filename = 'sample.gif';

// 1. The "explode/end" approach
$ext = end(explode('.', $filename));

// 2. The "strrchr" approach
$ext = substr(strrchr($filename, '.'), 1);

// 3. The "strrpos" approach
$ext = substr($filename, strrpos($filename, '.') + 1);

// 4. The "preg_replace" approach
$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename);

// 5. The "never use this" approach
// From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm
$exts = split("[/\\.]", $filename);
$n = count($exts)-1;
$ext = $exts[$n];

And the last but not the least:
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0

output:
/www/htdocs/inc
lib.inc.php
php
lib.inc

Office 2007 File Format MIME Types for HTTP Content Streaming

- by admin

Summary

Office 2007 introduced new file formats for common document types (Word documents, Excel spreadsheets, and PowerPoint presentations), and has standardized on new MIME types for each new format.  The following information is provided to document the new MIME types and their proper use in HTTP content streaming situations.

More Information

The following table documents the HTTP MIME types that are available when working with Office 2007 documents:

 















































































































Ext MIME Type
.doc application/msword
.dot application/msword
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm application/vnd.ms-word.document.macroEnabled.12
.dotm application/vnd.ms-word.template.macroEnabled.12
.xls application/vnd.ms-excel
.xlt application/vnd.ms-excel
.xla application/vnd.ms-excel
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlsm application/vnd.ms-excel.sheet.macroEnabled.12
.xltm application/vnd.ms-excel.template.macroEnabled.12
.xlam application/vnd.ms-excel.addin.macroEnabled.12
.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12
.ppt application/vnd.ms-powerpoint
.pot application/vnd.ms-powerpoint
.pps application/vnd.ms-powerpoint
.ppa application/vnd.ms-powerpoint
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.potx application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppam application/vnd.ms-powerpoint.addin.macroEnabled.12
.pptm application/vnd.ms-powerpoint.presentation.macroEnabled.12
.potm application/vnd.ms-powerpoint.presentation.macroEnabled.12
.ppsm application/vnd.ms-powerpoint.slideshow.macroEnabled.12

 

To fully support the new types, web server administrators are advised to add the MIME types for the Open XML formats to their web server metabase settings so as to add the correct MIME type header in documents saved directly on the server and sent back.  For Windows 2003 Servers running IIS 6.0, you can add the Open XML types in IIS Manager, Server Properties, MIME Types.  These new formats are included in Windows 2008 running IIS 7.0 by default.  For more details on the default MIME types for IIS, please see the following KB article:
936496: Description of the default settings for the MimeMap property and for the ScriptMaps property in IIS

Clients that install Office 2007 or the Office 2007 File Format Compatibility Pack will get client-side MIME mappings to these formats by default.

To use the MIME type in your ASP/ASP.NET code, you should use the built-in Response.ContentType property and set it to the MIME value that matches the content type you are providing.  If you fail to set the correct type, security checks by the client may prevent the content from being opened or may prompt the user with an alert that the file is not in the correct format.

PHP: explode() or split()?

- by admin

Actually explode() isn’t the same as split().

The biggest difference is that explode() takes in parameters a delimiter to split by, while split() takes a regular expression. This means that explode() runs faster. And even more, the PHP documentation says that preg_split() is faster than split(), so really there isn’t much of a reason to use split() at all.

split() is not an alias of explode() while join() is an alias of implode().

And finally:

split() function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

CSS Word-Wrap

- by admin

This property specifies whether the current rendered line should break if the content exceeds the boundary of the specified rendering box for an element (this is similar in some ways to the ‘clip’ and ‘overflow’ properties in intent.) This property should only apply if the element has a visual rendering, is an inline element with explicit height/width, is absolutely positioned and/or is a block element.

 

Examples








div { word-wrap: break-word } 

<div style=”word-wrap: break-word”>Here is some content for the div element</div>

 

Possible Values

















Value Description
normal Content will exceed the boundaries of the specified rendering box.
break-word Content will wrap to the next line when necessary, and a word-break will also occur if needed.

jsFiddle

- by admin

JsFiddle is a playground for web developers, a tool which may be used in many ways. One can use it as an online editor for snippets build from HTML, CSS and JavaScript. The code can then be shared with others, embedded on a blog, etc. Using this approach, JavaScript developers can very easily isolate bugs.

Decrypting XML File with Actionscript 2.0, memory problem?

- by admin

Q:

I have an encrypted XML file that needs to be decrypted and displayed in Flash. The Encrypted XML file contains over 33000 characters, Flash crashes when I try to decrypt it. Is there a limit to amount of data that Flash can decrypt? I'm using rijndael to decrypt and Actionscript 2.0.


Just that the script is causing the flash player to run slowly and if it continues to run, my computer may become unresponsive. It then asks me do I want to abort. If I don't, it just keeps reappearing. the only code in the file is to decrypt, so it isn't caused by anything else.

A:




Your problem is caused by the non-existing multithreading capabilities in Flash: All calculations are supposed to happen "in-between frames", i.e. user algorithms should not take longer to execute than the interval at which the screen is refreshed. If your calculation takes too long to finish, the Flash player will first start to drop frames, and (unless you changed settings) after 15 seconds show the warning you described.


You can get around this by "spreading" your algorithm across multiple frames, making sure only part of the calculation is executed until the screen is refreshed. You can do so by simply splitting up your encrypted string into small enough parts and executing an enterFrame loop to decrypt one at a time, or by implementing something like Alex Harui's PseudoThread class (which essentially does the same, but comes with encapsulation and all that Jazz).





VIM Editor Commands

- by admin

Vim is an editor to create or edit a text file.

There are two modes in vim. One is the command mode and another is the insert mode.
In the command mode, user can move around the file, delete text, etc.
In the insert mode, user can insert text.

Changing mode from one to another

From command mode to insert mode type a/A/i/I/o/O ( see details below)
From insert mode to command mode type Esc (escape key)

Some useful commands for VIM


Text Entry Commands (Used to start text entry)

a Append text following current cursor position
A Append text to the end of current line
i Insert text before the current cursor position
I Insert text at the beginning of the cursor line
o Open up a new line following the current line and add text there
O Open up a new line in front of the current line and add text there
The following commands are used only in the commands mode.

Cursor Movement Commands

h Moves the cursor one character to the left
l Moves the cursor one character to the right
k Moves the cursor up one line
j Moves the cursor down one line
nG or :n Cursor goes to the specified (n) line
(ex. 10G goes to line 10)
^F (CTRl F) Forward screenful
^B Backward screenful
^f One page forward
^b One page backward
^U Up half screenful
^D Down half screenful
$ Move cursor to the end of current line
0 (zero) Move cursor to the beginning of current line
w Forward one word
b Backward one word
Exit Commands
:wq Write file to disk and quit the editor
:q! Quit (no warning)
:q Quit (a warning is printed if a modified file has not been saved)
ZZ Save workspace and quit the editor (same as :wq)
: 10,25 w temp
write lines 10 through 25 into file named temp. Of course, other line
numbers can be used. (Use :f to find out the line numbers you want.

Text Deletion Commands

x Delete character
dw Delete word from cursor on
db Delete word backward
dd Delete line
d$ Delete to end of line
d^ (d caret, not CTRL d) Delete to beginning of line
Yank (has most of the options of delete)-- VI's copy commmand
yy yank current line
y$ yank to end of current line from cursor
yw yank from cursor to end of current word
5yy yank, for example, 5 lines
Paste (used after delete or yank to recover lines.)
p paste below cursor
P paste above cursor
"2p paste from buffer 2 (there are 9)
u Undo last change
U Restore line
J Join next line down to the end of the current line

File Manipulation Commands

:w Write workspace to original file
:w file Write workspace to named file
:e file Start editing a new file
:r file Read contents of a file to the workspace
To create a page break, while in the insert mode, press the CTRL key
And l. ^L will appear in your text and will cause the printer to start
A new page.

Other Useful Commands

Most commands can be repeated n times by typing a number, n, before
the command. For example 10dd means delete 10 lines.
. Repeat last command
cw Change current word to a new word
r Replace one character at the cursor position
R Begin overstrike or replace mode – use ESC key to exit
:/ pattern Search forward for the pattern
:? pattern Search backward for the pattern
n (used after either of the 2 search commands above to
continue to find next occurrence of the pattern.
:g/pat1/s//pat2/g replace every occurrence of pattern1 (pat1) with pat2
Example :g/tIO/s//Ada.Text_IO/g
This will find and replace tIO by Ada.text_IO everywhere in the file.
:g/a/s// /g replace the letter a, by blank
:g/a/s///g replace a by nothing
note: Even this command be undone by u

Examples

Opening a New File

Step 1 type vim filename (create a file named filename)
Step 2 type i ( switch to insert mode)
Step 3 enter text (enter your Ada program)
Step 4 hit Esc key (switch back to command mode)
Step 5 type :wq (write file and exit vim)

Editing the Existing File

Step 1 type vim filename (edit the existing file named filename)
Step 2 move around the file using h/j/k/l key or any appropriate command
h Moves the cursor one character to the left
l Moves the cursor one character to the right
k Moves the cursor up one line
j Moves the cursor down one line
nG or :n Cursor goes to the specified (n) line
(ex. 10G goes to line 10)
Step 3 edit required text (replace or delete or insert)
Step 4 hit Esc key (exit from insert mode if you insert or replace text)
Step 5 type :wq

How do you select a particular option in a SELECT element in jQuery?

- by admin

You can just use val() method:

$('#select').val('the_value');



For checkboxes, radios, and listboxes the command sets the "selected" attribute for those items.


« Newer posts