Taking Screenshot in perl - linux

i am running a perl script from a linux machine to log onto a router remotely to collect data. few of my client requirements include screenshots of specific configs.
i tried using
Imager::Screenshot
But each time it is printing a black screen. Is there a better way to capture screenshots of the router output, rather capturing the screenshot of the linux screen would work well for me as well.
Thanks in advance

Please refer this coding:
sub new {
my $class = shift;
my #params = ();
#params = #{shift()} if _ARRAY0($_[0]);
my $image = Imager::Screenshot::screenshot( #params );
unless ( _INSTANCE($image, 'Imager') ) {
Carp::croak('Failed to capture screenshot');
}
# Hand off to the parent class
return $class->SUPER::new( image => $image, #_ );
}
give thanks to: Taking Screenshot in perl

Related

Class 'Horde_String' not found in \pear\Horde\Text\Diff.php

I am trying to set up a class for tracking changes in the content by different authors. I did RnD and found text_Diff is the pear package which is responsible for the same. Later, text_diff is maintained at
'http://pear.horde.org/'
I am now trying to run the example
include_once "Text/Diff.php";
include_once "Text/Diff/Renderer.php";
$from_text=file('file.html');
$to_text=file('file_edited.html');
$diff = new Horde_Text_Diff($from_text, $to_text);
$renderer = new Horde_Text_Diff_Renderer();
echo $renderer->render($diff);
and I am getting the error 'Horde_String'
I am not able to find class, any one has idea about this class?. There are multiple Engine like "Native","XDiff","String" and "Shell" ...but I am not able to find what are they and when you use which one..
any help to resolve this error will be a great help.
Thanks
I struggled for hours trying to get this to work. In the end I had to install Horde_Text_Diff by entering the commands (installs the Autoloader described in the linked question in the comment by Keelan):
pear install Horde_Autoloader
pear install Horde_Text_Diff
This installs the packages I believe you need. Then, you need to properly call the autoloader package by tweaking the following code to match the paths for your system.
require_once 'Horde/Autoloader.php';
require_once 'Horde/Autoloader/ClassPathMapper.php';
require_once 'Horde/Autoloader/ClassPathMapper/Default.php';
$autoloader = new Horde_Autoloader();
$autoloader->addClassPathMapper( new Horde_Autoloader_ClassPathMapper_Default('/usr/share/pear') );
$autoloader->registerAutoloader();
Then, if all goes well you should be able to call and use the class by doing something like the following:
$check_diff = new Horde_Text_Diff( $engine = 'auto', $params = array( $from_text, $to_text ) );
$renderer = new Horde_Text_Diff_Renderer_Inline();
echo $renderer->render($check_diff);
Although this isn't totally working for me yet as I'm finding that it only compares the first characters in the strings. Which is a new problem unrelated to getting the class to work :)
Here is my approach, which does not use the Hoard autoloader:
spl_autoload_register(function ($class_name) {
if (substr($class_name, 0, strlen('Horde_')) != 'Horde_')
return false;
$file = substr($class_name, strlen('Horde_')); // omit if not needed
$file = str_replace("_", DIRECTORY_SEPARATOR, $file);
return include_once($file . '.php');
});
function diff($old, $new)
{
$td = new Horde_Text_Diff('auto', array($old, $new));
$rend = new Horde_Text_Diff_Renderer_Unified();
return $rend->render($td);
}

Can we get MathML output from MathJax

I was wondering if there are ways to convert MathJax output to MathML.
I read through several articles that saying MathJax supports MathML. I can also see the option 'Show MathML' when I right click the MathJax formulas. My question is, can I get the MathML output to the webpage from MathJax? I am not familiar with MathJax and I am not sure how it works. Any resources or tutorial pages would have been nice!
#Peter, I think the OP may be asking how to get a MathML string from MathJax, rather than how to insert the MathML tags into the page directly. So perhaps the discussion on the MathJax forums that describes how to use toMathML will do the trick.
The basic idea is to get the element jax (using MathJax.Hub.getAllJax) for the math you want to convert, then to call its toMathML method. But you need to use some care for this, as toMathML can operate asynchronously. The link above goes through the details.
EDIT: The MathJax-node project allows you to do this from the command line, so you might want to check that out as well.
I have written some code check it out:
First include "https://code.jquery.com/jquery-1.11.2.min.js" and "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
var JaxToML = {
toMathML: function(jax, callback) {
var mml;
try {
mml = jax.root.toMathML("");
} catch (err) {
if (!err.restart) {
throw err
} // an actual error
return MathJax.Callback.After([JaxToML.toMathML, jax, callback], err.restart);
}
MathJax.Callback(callback)(mml);
},
convert: function(AjaxText, callback) {
var tempDiv = $('<div style="width:455px;height:450px:border-width:thick;border-style:double;"></div>').appendTo("body").html(AjaxText)[0];
MathJax.Hub.Queue(["Typeset", MathJax.Hub, tempDiv]); //first place in Q
MathJax.Hub.Queue(function() { //wait for a callback to be fired
var jax = MathJax.Hub.getAllJax(tempDiv);
for (var i = 0; i < jax.length; i++) {
JaxToML.toMathML(jax[i], function(mml) {//alert(jax[i].originalText + "\n\n=>\n\n"+ mml);
AjaxText = AjaxText.replace(jax[i].originalText, mml);
});
}
$(tempDiv).remove();
AjaxText = AjaxText.replace(/\(/g,""); //notice this escape character for ( - i.e it has to be \( , know why it is beacuse JS will treat ) or ( as end/begin of function as there are no quotes here.
AjaxText = AjaxText.replace(/\)/g,""); //notice this escape character for ) - i.e it has to be \)
AjaxText = AjaxText.replace(/\\/g,"");
callback(AjaxText);
});
},
};
Usage :
JaxToML.convert(AjaxText, function(mml) {
alert(mml);
});
The MathJax documentation on configuring MathJax is probably the place to start reading. You can configure the output jax per browser.
A word of caution. There's a reason why MathJax does not use to MathML output on any browser right now: browser support isn't quite there yet. (This will change as browsers catch up and MathJax can start to leverage their native support.) So make sure your content actually renders ok.

Wordpress Plugin: Facebook comments box position

I have a problem with the "new" Facebook plugin for Wordpress. I would like to re-position it on my post page. I've read somewhere else (or maybe here) that you could use the comment box from developers.facebook.com but I want to use the original Facebook plugin. So here goes:
I've found (in the plugin folder) where Facebook have put the code to install comments box in my theme. It looks like this:
public static function the_content_comments_box( $content ) {
global $post;
if ( ! isset( $post ) )
return;
$options = get_option( 'facebook_comments' );
if ( ! is_array( $options ) || empty( $options ) )
return $content;
// closed posts can have comments from their previous open state
// display noscript version of these comments
$content .= "\n" . self::comments_markup( 'noscript' ) . "\n";
// no option via JS SDK to display comments yet not accept new comments
// only display JS SDK version of comments box display if we would like more comments
if ( comments_open( $post->ID ) ) {
$url = apply_filters( 'facebook_rel_canonical', get_permalink() );
if ( $url ) // false could happen. let JS SDK handle compatibility mode
$options['href'] = $url;
$content .= self::js_sdk_markup( $options );
}
return $content;
}
}
How do put the Facebook comments box in the bottom of my post page?
You can look at a random post page here: My temporary site What I'm ultimately trying to do is to have Facebook Comments box after Relaterede indlæg (related posts).
Is this at all possible?
I don't use the FB plugins for Wordpress because they seem bloated to me. However, here's a simple one-line code that I use to add a facebook comments box. You can place it anywhere in any template.
<div class="fb-comments" data-href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ?>"></div>
PLEASE NOTE: this method requires that you have the Facebook SDK installed on the site. Also, it won't work as a widget unless you have enabled the ability to execute PHP in your widgets (requires a plug-in).

Drupal autocomplete fails to pull out data as a subdomain

I managed to pull out data using autocomplete at my local (http://mysite.dev/swan/autocomplete). The json data is displayed.
But when I applied the same module at live (now a subdomain: http://test.mysite.com/swan/autocomplete with different drupal installs), this autocomplete fails to pull out data. No json data is displayed.
Do you have any idea if this is related to cross domain issue, or any possible cause I might not be aware of?
This is the callback:
/**
* Callback to allow autocomplete of organisation profile text fields.
*/
function swan_autocomplete($string) {
$matches = array();
$result = db_query("SELECT nid, title FROM {node} WHERE status = 1 AND type='organisation' AND title LIKE LOWER ('%s%%')", $string, 0, 40);
while ($obj = db_fetch_object($result)) {
$title = check_plain($obj->title);
//$matches[$obj->nid] = $title;
$matches[$title] = $title;
}
//drupal_json($matches); // fails at safari for first timers
print drupal_to_js($matches);
exit();
}
Any hint would be very much appreciated.
Thanks
It's the conflict with password_policy.module. Other similar modules just do the same blocking. These modules stop any autocomplete query.

Embed node creation form using PHP

I have a content type called "enquiry". I want to embed the node creation form at various places throughout my website. How do I do this via PHP?
sounds like a job for the webform module. if you really want to go the cck route you can try something like this:
$node = new stdClass();
$node->type = 'store_review';
module_load_include('inc', 'node', 'node.pages');
$output = drupal_get_form('store_review_node_form', $node);
print $output;
ref: http://drupal.org/node/464906
Solution:
$node = new stdClass();
$node->type = 'enquiry';
module_load_include('inc', 'node', 'node.pages');
$output = drupal_get_form('enquiry_node_form', $node);
print $output;

Resources