While developing a while back I needed a way to use programming to copy text to a user's clipboard without using Flash (recent versions of Flash restrict this anyway). The solution was pretty easy and handled by JavaScript.
Problem: Needed to copy text to clipboard in Chrome without using Flash and when a user clicked a link. Chrome (and most likely other browsers) restrict this copying to prevent malicious activity. While this is helpful to user's it can also be unhelpful to programmers.
Solution: To accomplish this I started out testing what could be copied and found that only text inside a form input control could be copied using execCommand. This helped me to understand that my first objective was to create a form input and copy the text inside it. Once I was able to do this, I decided to create the input field with JavaScript, then set the value of it with JavaScript, then run my execCommand function. This worked. The last thing I needed to do was to hide the form input control so that the user didn't see it popup every time they copied something. Using CSS I was able to make the form input mostly unnoticeable. CSS is not required for the solution to work, but helped to make things less noticeable.
When all was said and done, my script works fine in Chrome. I will test it in other browsers and see how it performs.
Note: Making a form input hidden with CSS will prevent JavaScript from selecting it to add it to the clipboard. As you will notice in my solution, I always kept the input visible. My code is shown using jQuery but can be easily done without it.
Code:
$("<input />") // Create the element
.attr('id','custom_input') // this may be unnecessarily -- the CSS below helps to hide the input
.css({width:'1px', height:'1px', border:'none', backgroundColor:'#FFF', 'position':'absolute'})
.prependTo($(t).parent()) // in my case this is document root -- this may
.val($('#element_id').html())
.focus()
.select();
document.execCommand("copy", false, null);
If you have questions regarding implementing this code or non-jQuery versions, do let me know.
Best of luck.
Tuesday, June 29, 2010
Wednesday, June 16, 2010
Symfony 1.4 uploads FLV as EXE or BIN files
When transferring a project from our development server to our production server at work, I realized that uploading FLV files resulted in the end result being a .BIN (or binary file). Oddly this didn't happen on the development server, only the production server. After verifying everything I could think of between the two servers, I finally decided on a solution.
Problem:
Symfony uploading FLV files as BIN files (or sometimes EXE on Windows).
More Information:
Symfony has a big associated array of mime-types and file extensions, one that specifies 'application/octet-stream' as being associated with the file type BIN.
Solution:
I tried manually changing the sfValidatedFile.class.php file in lib/vendor/symfony/lib/validator/ but it didn't help. To solve this problem, I ended up manually checking the file's extension before and after upload and then correcting it if it was wrong. If I come up with a better solution, I will definitely post my findings.
Good luck.
Problem:
Symfony uploading FLV files as BIN files (or sometimes EXE on Windows).
More Information:
Symfony has a big associated array of mime-types and file extensions, one that specifies 'application/octet-stream' as being associated with the file type BIN.
Solution:
I tried manually changing the sfValidatedFile.class.php file in lib/vendor/symfony/lib/validator/ but it didn't help. To solve this problem, I ended up manually checking the file's extension before and after upload and then correcting it if it was wrong. If I come up with a better solution, I will definitely post my findings.
Good luck.
Friday, April 23, 2010
ll equivalent in Debian Linux
Problem:
Want to see files with sizes and permissions on debian linux like you can with RH (Red Hat) linux distros.
More Info:
ll is an alias for the file structure listing command ls.
Solution:
View files, file sizes, and permissions on debian ls -hal.
Want to see files with sizes and permissions on debian linux like you can with RH (Red Hat) linux distros.
More Info:
ll is an alias for the file structure listing command ls.
Solution:
View files, file sizes, and permissions on debian ls -hal.
Sunday, April 18, 2010
Fixing the CW Player
Problem:
My wife and I enjoy watching shows on the CW TV but have recently found that we began being greeted with the player showing a screen saying it was updating the player.
Tech Talk: The player they use is called the Move Media Player. It is a program that you have to have specifically installed on your computer to play video content from CW site as well as many other websites. It does have some tracking software that helps them track you across several websites, but doesn't expose your personal information or data.
Solution:
After trying many different scenerios with several browsers and uninstalling reinstalling the Move Media Player found in the installed programs list on Window Vista or XP. I was finally able to diagnose some of the problem and figure out a solution. Uninstall the Move Media Player from your computer (Start -> Control Panel->Uninstall a program [on Windows Vista/ similar on Windows XP]). Once you have removed the Move Media Player, use Internet Explorer and navigate to your shows web page. When the place where video normally shows gives you the option to download and install the Move Media Player, do so. Complete the installation. You shouldn't have to do anything at that point other than wait.
More Information: Google Chrome is not said to be supported at this time, so it most likely wont help you resolve this problem. I originally tried to use Firefox to reinstall the Move Media Player, but continued to trace an error. Firefox did work however when I retried it later. If you have specific questions about this issue, feel free to leave a comment and I will help you the best I can.
Happy television watching.
My wife and I enjoy watching shows on the CW TV but have recently found that we began being greeted with the player showing a screen saying it was updating the player.
Tech Talk: The player they use is called the Move Media Player. It is a program that you have to have specifically installed on your computer to play video content from CW site as well as many other websites. It does have some tracking software that helps them track you across several websites, but doesn't expose your personal information or data.
Solution:
After trying many different scenerios with several browsers and uninstalling reinstalling the Move Media Player found in the installed programs list on Window Vista or XP. I was finally able to diagnose some of the problem and figure out a solution. Uninstall the Move Media Player from your computer (Start -> Control Panel->Uninstall a program [on Windows Vista/ similar on Windows XP]). Once you have removed the Move Media Player, use Internet Explorer and navigate to your shows web page. When the place where video normally shows gives you the option to download and install the Move Media Player, do so. Complete the installation. You shouldn't have to do anything at that point other than wait.
More Information: Google Chrome is not said to be supported at this time, so it most likely wont help you resolve this problem. I originally tried to use Firefox to reinstall the Move Media Player, but continued to trace an error. Firefox did work however when I retried it later. If you have specific questions about this issue, feel free to leave a comment and I will help you the best I can.
Happy television watching.
Friday, March 26, 2010
Flash Builder 4 / Flex 4 - Where did the icon property go?
Problem:
In previous versions of Flex (when using Halo), it was simple to add an icon to a button. But now with the Spark theming, there is no such convenience. I went in search of a solution online and after much digging where others had written custom components and so on, I found a solution posted by Adobe and its incredibly simple.
Solution:
Just create a new theme extending the Spark button skin, and then make two line replacements. Instead of me reexplaining it, just read it on Adobe's website.
http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7d9f.html
Good luck.
In previous versions of Flex (when using Halo), it was simple to add an icon to a button. But now with the Spark theming, there is no such convenience. I went in search of a solution online and after much digging where others had written custom components and so on, I found a solution posted by Adobe and its incredibly simple.
Solution:
Just create a new theme extending the Spark button skin, and then make two line replacements. Instead of me reexplaining it, just read it on Adobe's website.
http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7d9f.html
Good luck.
Monday, March 15, 2010
Strange "Connection closed by 127.0.0.1" in log files every minute
Recently I had been installing different types of software to help me track my server. Some days after doing this however, my server started reporting a strange message in the log files.
Problem:
The following would show up in my logs with a different GUID and timestamp of course on one minute intervals.
Solution:
To solve this mystery I began trying to think of the possibilities of what it could be. What had I just installed that would be doing this? My memory sucks and I couldn't remember, so I began looking through the web to see if anyone had any solutions. A coworker of mine suggested using a netstat command ("netstat -lep --tcp") to see what services were running and which ones were newly installed on my server. I went through and turned off the services one at a time until I found the culprit. Monit had been installed some days earlier but the configuration file had errored out producing the message above in my log. Stopping the service ("/sbin/service monit stop"), the error no longer appeared in the log file. With some fixing, I am sure the wrongs in the Monit config file could be made right, but for now I am just going to keep it off.
Hope this helps someone else with the same issue. Good luck.
Problem:
The following would show up in my logs with a different GUID and timestamp of course on one minute intervals.
Mar 15 13:03:27 server 1 sshd[16979]: Connection closed by 127.0.0.1
Solution:
To solve this mystery I began trying to think of the possibilities of what it could be. What had I just installed that would be doing this? My memory sucks and I couldn't remember, so I began looking through the web to see if anyone had any solutions. A coworker of mine suggested using a netstat command ("netstat -lep --tcp") to see what services were running and which ones were newly installed on my server. I went through and turned off the services one at a time until I found the culprit. Monit had been installed some days earlier but the configuration file had errored out producing the message above in my log. Stopping the service ("/sbin/service monit stop"), the error no longer appeared in the log file. With some fixing, I am sure the wrongs in the Monit config file could be made right, but for now I am just going to keep it off.
Hope this helps someone else with the same issue. Good luck.
Friday, March 5, 2010
Problems starting Dimdim 4.5 Open Source
When trying to install Dimdim 4.5 CentOS RPM on my CentOS 5.4 server, I had to modify several files to get things to work in addition to the standard installation instructions.
Problem:
Starting dimdim displayed several errors when starting up. It would work just fine except for sharing documents. This always produced the error: 'The document conversion failed with error: document id generation failed.'. Looking closer to the start up errors and doing some google searching I finally figured out how to get documents to upload and display.
Revert my openoffice 3.1 back to openoffice 3.0. Significant changes between the version of open office cause issues with calling required modules. You can use yum to remove the current openoffice rpm (will be several rpms).
You can find the rpm for open office 3.0 here.
You will need to gunzip and tar the file to unpack it. Once you have done that you can follow the directions here to install them.
Restart dimdim.
Problem:
Starting dimdim displayed several errors when starting up. It would work just fine except for sharing documents. This always produced the error: 'The document conversion failed with error: document id generation failed.'. Looking closer to the start up errors and doing some google searching I finally figured out how to get documents to upload and display.
Traceback (most recent call last):Solution:
File "/usr/local/dimdim/Mediaserver/mods/interface.py", line 7, in
from document_manager.slidedeck import CSlidedeck
File "/usr/local/dimdim-4.5/Mediaserver/mods/document_manager/slidedeck.py", line 22, in
from engine import exportEngine
File "/usr/local/dimdim-4.5/Mediaserver/mods/document_manager/engine.py", line 34, in
import uno
File "/opt/meeting/lib/python2.5/uno.py", line 33, in
import pyuno
SystemError: dynamic module not initialized properly
Revert my openoffice 3.1 back to openoffice 3.0. Significant changes between the version of open office cause issues with calling required modules. You can use yum to remove the current openoffice rpm (will be several rpms).
You can find the rpm for open office 3.0 here.
You will need to gunzip and tar the file to unpack it. Once you have done that you can follow the directions here to install them.
Restart dimdim.
Subscribe to:
Comments (Atom)