Tuesday, 10 September 2013

save the output from telnet

save the output from telnet

i'm already create the telnet with java, but i have no idea how to save
the output into file.. can help'me?? this is my code...
this is for connect to the target
public class telnetsample
{
private static TelnetClient telnet = new TelnetClient();
private InputStream in;
private PrintStream out;
private char prompt = '$';
public telnetsample( String server, String username, String password
, String command) {
try {
// Connect to the specified server
telnet.connect( server, 23 );
// Get input and output stream references
in = telnet.getInputStream();
out = new PrintStream( telnet.getOutputStream() );
// Log the user on
readUntil( "Username: " );
write( username );
readUntil( "Password: " );
write( password );
readUntil ("hostname");
write (command);
// Advance to a prompt
readUntil( prompt + " " );
}
catch( Exception e ) {
e.printStackTrace();
}
}
this is for read the command on the terminal
public String readUntil( String pattern ) {
try {
char lastChar = pattern.charAt( pattern.length() - 1 );
StringBuffer sb = new StringBuffer();
boolean found = false;
char ch = ( char )in.read();
while( true ) {
System.out.print( ch );
sb.append( ch );
if( ch == lastChar ) {
if( sb.toString().endsWith( pattern ) ) {
return sb.toString();
}
}
ch = ( char )in.read();
}
}
catch( Exception e ) {
e.printStackTrace();
}
return null;
}
for send the command
public void write( String value ) {
try {
out.println( value );
out.flush();
System.out.println( value );
}
catch( Exception e ) {
e.printStackTrace();
}
}
for insert username etc
public static void main( String[] args ) {
try {
telnetsample telnet = new telnetsample( "ip",
"user",
"password",
"command");
}
catch( Exception e ) {
e.printStackTrace();
}
System.exit(0);
Runtime.getRuntime().exit(0);
}
}

rendering one item from a list in Ember

rendering one item from a list in Ember

In my Ember app, I get a list of all the restaurants using an ajax call
copied from Discourse co-founder's blog post
http://eviltrout.com/2013/02/27/adding-to-discourse-part-1.html
App.Restaurant.reopenClass({
findAll: function() {
return $.getJSON("restaurants").then(
function(response) {
var links = Em.A();
response.restaurants.map(function (attrs) {
links.pushObject(App.Restaurant.create(attrs));
});
return links;
}
);
},
I have a Restaurants route set up which calls the findAll shown above and
renders it into the application template
App.RestaurantsRoute = Ember.Route.extend({
model: function(params) {
return(App.Restaurant.findAll(params));
},
renderTemplate: function() {
this.render('restaurants', {into: 'application'});
}
});
The restaurants are displayed as a restaurants template like this with a
link to each individual restaurant. I've also included the restaurant
template
<script type="text/x-handlebars" id="restaurants">
<div class='span4'>
{{#each item in model}}
<li> {{#link-to 'restaurant' item}}
{{ item.name }}
</li>
{{/each}}
</ul>
</div>
<div class="span4 offset4">

</div>
</script>
In the Ember router, I have a parent/child route set up like this
this.resource("restaurants", function(){
this.resource("restaurant", { path: ':restaurant_id'});
});
Therefore, I'm hoping that when I click on the link to a particular
restaurant in the restaurants list, it'll insert this restaurant template
into the outlet defined in the restaurantS (plural) template
<script type="text/x-handlebars" id="restaurant">
this text is getting rendered
{{ item }} //item nor item.name are getting rendered
</script>
This restaurant template is getting rendered, however, the data for the
item is not getting displayed.
When I click {{#link-to 'restaurant' item}} in the list, item represents
that restaurant.
In this setup, does Ember need to make another ajax call to retrieve that
particular item, even though it's already been loaded from the findAll
call?
In the event that I do need to query for the individual restaurant (again)
I created a new route for the individual restaurant
App.RestaurantRoute = Ember.Route.extend({
model: function(params) {
console.log(params);
console.log('resto');
return App.Restaurant.findItem(params);
}
});
and a findItem on the Restaurant model
App.Restaurant.reopenClass({
findItem: function(){
console.log('is this getting called? No...');
return 'blah'
}
but none of those console.logs are getting called.
In the Ember starter video https://www.youtube.com/watch?v=1QHrlFlaXdI,
when Tom Dale clicks on a blog post from the list, the post appears in the
template defined for it without him having to do anything more than set up
the routes (as I did) and the {{outlet}} within the posts template to
receive the post.
Can you see why the same is not working for me in this situation?

Temporarily store User id when loading user page for multiple views/controllers

Temporarily store User id when loading user page for multiple
views/controllers

I want to create a multi user app with no authentication.
I want to have unique urls for each user and assume they will not know
other people's urls. So when user visits a user page, I want to store that
id and use it provide a nav link (to setup a nav like 'my page | feed page
| some other page')
I've been trying to figure out how to use current_user=sessions[:user_id]
in the Application Controller but am getting lost.

web app to mobile app

web app to mobile app

Am new into mobile app development but I have a web application i built
using jquery mobile its actually suppose to be a mobile application but it
all in html, css, php and javascript. it runs good on a browser and i can
loadit up from my wamp server but it originally suppose to be a phone app
how can i turn that into a phone app. I have tried sencha, and my xdk does
not even load. I need help cause i dont want to end up re-coding the
entire app; i just want to use my existing .html file and .css and and .js
and i understand their are some basic event handlers that will be
different from event handler on a web browser. Anyhelp is appreaciated.
Thanks

What is the LifeCycle of VM

What is the LifeCycle of VM

&#65279;&#65279;The Component that Start VM is we referred as Launcher, is
this launcher (ie java/javaws Other Launchers like JNI
(&#65279;&#65279;JNI_CreateJavaVM) command) follow this Lifecycle.
Typically the Process what we see when we invoke this command
Parsing of Command Line.
Heap Initialization
Lookup the Main Class.
Create the HotSpot VM using Native call.
Execute the main Class
Perform the CLeanup Operation
Is something more goes when the VM life cycle Initiate

Responsive Javascript Slider with Multibox

Responsive Javascript Slider with Multibox

I want to make Slider like showing me a three slide at a time, like bit
small size images both side and middle image with large size, and when i
click on arrow this will show me a second images that right now we can see
on side image like below image.

Please help to find me slider like i tell you, thanks a lot in advance

Why is this jQuery Validation not working on IE 7/8?

Why is this jQuery Validation not working on IE 7/8?

I'm encountering a small problem with a client-side validation script
which works on all browsers including IE 9 / 10, but is giving me
headaches on IE 7 and IE 8.
The page with the form which needs this validation can be accesed over
here and someone must definetly take a look in order to give a good
answer.
And here's the validation script I use for the form:
jQuery(document).ready(function(){
jQuery("#adaugareanunt").submit(function(event){
errornotice = jQuery("#eroareadaugare");
emptyerror = "Necompletat";
emailerror = "Email incorect";
email = jQuery('#contactEmail');
descriere = jQuery('#descriptionro_RO');
jQuery('#adaugareanunt input[type="text"]').each(function(){
if ((jQuery(this).val() == "") || (jQuery(this).val() ==
emptyerror)) {
jQuery(this).addClass("campuri-necesare");
jQuery(this).val(emptyerror);
errornotice.fadeIn(750);
} else {
jQuery(this).removeClass("campuri-necesare");
}
});
jQuery('#adaugareanunt select').each(function(){
if ((jQuery(this).val() == "")) {
jQuery(this).addClass("campuri-necesare");
errornotice.fadeIn(750);
} else {
jQuery(this).removeClass("campuri-necesare");
}
});
if(descriere.val() == "" || descriere.val() == emptyerror) {
descriere.addClass("campuri-necesare");
descriere.val(emptyerror);
errornotice.fadeIn(750);
} else {
descriere.removeClass("campuri-necesare");
}
if
(!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val()))
{
email.addClass("campuri-necesare");
email.val(emailerror);
}
if (jQuery(":input").hasClass("campuri-necesare")) {
return false;
}
});
// Clears any fields in the form when the user clicks on them
jQuery(":input").focus(function(){
if (jQuery(this).hasClass("campuri-necesare") ) {
jQuery(this).val("");
jQuery(this).removeClass("campuri-necesare");
}
});
});
Any hints?
Thanks!