Hi experts,
Assuming you've already had a chance to look through the lambda syntax proposed for Java7 (and the other things that have happened with Java, after Oracle has bought Sun + obvious problems in Java Community Process), what do you think is the future of Java language? Should I, as a Java greenhorn, invest time in learning Java language (not talking about the core JVM, which definitely will survive anything, and worth investments), or concentrate on Scala, Groovy, or other hybrid languages on the JVM platform (I've came into Java world from PHP/Ruby).
Thanks in advance.
Right now, I do a
get '/' do
set :base_url, "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}"
# ...
haml :index
end
to be able to use options.base_url in the HAML index.haml.
But I am sure there is a far better, DRY, way of doing this. Yet I cannot see, nor find it. (I am new to Sinatra :))
Somehow, outside of get, I don't have request.env available, or so it seems. So putting it in an include did not work.
How do you get your base url?
I have several classes that extend C and I would need a method that accepts any argument of type C. But in this method I would like to know if I'm dealing with A or B.
*
public A extends C
public B extends C
public void goForIt(C c)()
If I cast how can I retrieve the type in a clean way (I just read using getClass or instanceof is often not the best way).
*Sorry but I can't type closing braces
I'm learning java and one thing I've found that I don't like, is generally when I have code like this:
import java.util.*;
import java.io.*;
public class GraphProblem
{
public static void main(String[] args)
{
if (args.length < 2)
{
System.out.println("Error: Please specify a graph file!");
return;
}
FileReader in = new FileReader(args[1]);
Scanner input = new Scanner(in);
int size = input.nextInt();
WeightedGraph graph = new WeightedGraph(size);
for(int i = 0; i < size; i++)
{
graph.setLabel(i,Character.toString((char)('A' + i)));
}
for(int i = 0; i < size; i++)
{
for(int j = 0; j < size; j++)
{
graph.addEdge(i, j, input.nextInt());
}
}
// .. lots more code
}
}
I have an uncaught exception around my FileReader.
So, I have to wrap it in a try-catch to catch that specific exception. My question is does that try { } have to encompass everything after that in my method that wants to use either my FileReader (in) or my Scanner (input)?
If I don't wrap the whole remainder of the program in that try statement, then anything outside of it can't access the in/input because it may of not been initialized or has been initialized outside of its scope. So I can't isolate the try-catch to just say the portion that intializes the FileReader and close the try statement immediately after that.
So, is it the "best practice" to have the try statement wrapping all portions of the code that are going to access variables initialized in it?
Thanks!
Is there any tool or software to find passphrases in an image like .jpg? or Should i use any programming in this regard, i googled but din't find any guidance?
How can I interact with objects I've created based on their given attributes in Ruby?
To give some context, I'm parsing a text file that might have several hundred entries like the following:
ASIN: B00137RNIQ
-------------------------Status Info-------------------------
Upload created: 2010-04-09 09:33:45
Upload state: Imported
Upload state id: 3
I can parse the above with regular expressions and use the data to create new objects in a "Product" class:
class Product
attr_reader :asin, :creation_date, :upload_state, :upload_state_id
def initialize(asin, creation_date, upload_state, upload_state_id)
@asin = asin
@creation_date = creation_date
@upload_state = upload_state
@upload_state_id = upload_state_id
end
end
After parsing, the raw text from above will be stored in an object that look like this:
[#<Product:0x00000101006ef8 @asin="B00137RNIQ", @creation_date="2010-04-09 09:33:45 ", @upload_state="Imported ", @upload_state_id="3">]
How can I then interact with the newly created class objects? For example, how might I pull all the creation dates for objects with an upload_state_id of 3? I get the feeling I'm going to have to write class methods, but I'm a bit stuck on where to start.
I'm very new to Version Control, and I was wondering if I could get some advice on how it can fit into website design.
At the moment I'm working on a typical, simple website that includes images:
A few .html files and a .css file
One folder full of photographs
Another folder with the corresponding thumbnails
Can I just put the whole lot in a repository? Or is there a better way I could apply Version Control to it? How should I deal with the images?
edit:
How well will it work with changes to the images? What if I decide to try and optimise my photographs or resize them. I wont be able to see what exactly changed about the images, should comments be enough to keep track of that?
I consider myself quite fluent in PHP and am rather familiar with nearly all of the important aspects and uses, as well as its pratfalls. This in mind, I think the major problem in taking on Perl is going to be with the syntax. Aside from this (a minor hindrance, really, as I'm rather sold on the fact that Perl's is far more readable), what are some key differences you think I should make myself aware of prior to taking on the language?
Dear All,
I am experienced in the technical support like Linux, oracle, sunos etc and but if i say scripting i know little bit of bash. Now i promoted to manage technical engineers inuding some java script developers, so i want to learn java scripting so that i can understand engineers. Hope you understand. Can you please advise me how can i start java scripting and point me to some simple docs and examples.
I am writing a small jQuery plugin to update a set of Divs with content obtained using Ajax calls. Initially, let's assume we have 4 divs. I am doing something like this:
(function($) {
....
....
//main function
$.fn.jDIV = {
init: function() {
...
...
for(var i = 0; i < numDivs; i++) {
this.query(i);
}
this.handlers();
},
query: function(divNum) {
//Makes the relevant ajax call
},
handlers: function() {
for(var i = 0; i < numDivs; i++) {
setInterval("$.fn.jDIV.query(" + i + ")", 5000);
}
}
};
})(jQuery);
I would like to be able to enable and disable a particular ajax query. I was thinking of adding a "start" and "stop" instead of the "handlers" function and subsequently storing the setInterval handler like this:
start: function(divNum) {
divs[divNum] = setInterval("$.fn.jDIV.query(" + i + ")", 5000);
},
stop: function(divNum) {
clearInterval(divs[divNum]);
}
I did not use jQuery to setup and destroy the event handlers. Is there a better approach (perhaps using more of jQuery) to achieve this?
I'm using c++ in visual studio express to generate random expression trees for use in a genetic algorithm type of program.
Because they are random, the trees often generate (I'll call them exceptions, I'm not sure what they are)
Thanks to a suggestion by George, I turned the mask _MCW_EM on so that hardware interrupts are turned off. (the default)
So, the program runs uninterrupted, but some of the values returned are: -1.#INF, -1.#NAN, -1.#INV.
I don't know how to identify these so that I can throw an exeption:
if ( variable == -1.#INF) ??
DigitalRoss in this post seemed to have the solution, but as I understood it I couldn't make it work.
I've been looking all over the place for this simple bit of code, that I assumed would be used all
the time, but have had no luck.
thanks
I have came across this problem a few times and can't seem to figure out a simple solution.
Say I have a string
string = "a=0 b=1 c=3"
I want to convert that into a dictionary with a, b and c being the key and 0, 1, and 3 being their respective values (converted to int). Obviously I can do this:
list = string.split()
dic = {}
for entry in list:
key, val = entry.split('=')
dic[key] = int(val)
But I don't really like that for loop, It seems so simple that you should be able to convert it to some sort of list comprehension expression. And that works for slightly simpler cases where the val can be a string.
dic = dict([entry.split('=') for entry in list])
However, I need to convert val to an int on the fly and doing something like this is syntactically incorrect.
dic = dict([[entry[0], int(entry[1])] for entry.split('=') in list])
So my question is: is there a way to eliminate the for loop using list comprehension? If not, is there some built in python method that will do that for me?
There's a few mentions of Javascript newbies getting starting by checking out some of Douglas Crockford's work (http://stackoverflow.com/questions/11246/best-resources-to-learn-javascript), but none of his resources seem to be for those looking to learn from the ground up.
Are there any suggestions for complete beginners regarding how best to learn JavaScript?
Personally I have plenty of HTML and CSS experience, and some PHP (which would help learning JS), but for those that don't know any programming language what would you recommend?
Hi all
I am a newbie to the python. Can I unhash, or rather how can I unhash a value. I am using std hash() function. What I would like to do is to first hash a value send it somewhere and then unhash it as such:
#process X
hashedVal = hash(someVal)
#send n receive in process Y
someVal = unhash(hashedVal)
#for example print it
print someVal
Thx in advance
My first post here (anywhere for that matter!), re. Cocoa/Obj-C (I'm NOT up to speed on either, please be patient!). I hope I haven't missed the answer already, I did try to find it.
I'm an old-school procedural dog (haven't done any programming since the mid 80's, so I probably just can't even learn new tricks), but OOP has my head spinning! My question is:
is there any means at all to
"discover/find/identify" an instance
of an object of a known class, given
that some OTHER unknown process
instantiated it?
eg. somthing that would accomplish this scenario:
(id) anObj = [someTarget getMostRecentInstanceOf:[aKnownClass class]];
for that matter, "getAnyInstance" or "getAllInstances" might do the trick too.
Background: I'm trying to write a plugin for a commercial application, so much of the heavy lifting is being done by the app, behind the scenes.
I have the SDK & header files, I know what class the object is, and what method I need to call (it has only instance methods), I just can't identify the object for targetting.
I've spent untold hours and days going over Apples documentation, tutorials and lots of example/sample code on the web (including here at Stack Overflow), and come up empty. Seems that everything requires a known target object to work, and I just don't have one.
Since I may not be expressing my problem as clearly as needed, I've put up a web page, with diagram & working sample pages to illustrate:
http://www.nulltime.com/svtest/index.html
Any help or guidance will be appreciated! Thanks.
I have the following struct:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct cAuthLogonChallenge
{
byte cmd;
byte error;
fixed byte name[4];
public cAuthLogonChallenge()
{
cmd = 0x04;
error = 0x00;
name = ???
}
}
name is supposed to be a null-terminated ASCII string, and Visual Studio is rejecting all my ideas to interact with it. How do I set it?
hello!
I'm trying to output multiline text with GD+PHP but can't get it working. my php knowledge is really basic.
here's the code, any idea on how to output 2 or 3 lines of text?
$theText = (isset($_GET['caption']))? stripslashes($_GET['caption']) :'';
imagettftext($baseImage, $textSize, $textAngle, $textXposition, $textYposition, $textColor, $fontName, $theText);
import math
def gen_caller(a):
for z in a:
x,y=z
if x==1:
x=2
if y>=x and y-x<=100000:
for i in range(x,y+1):
flag=0
for j in range(2,(long(math.sqrt(i))+1)):
if(i%j==0):
flag=1
break
if flag==0:
print i
print ""
n=(int(raw_input()))
gen_caller([[(long(raw_input())) for j in range(0,2)] for i in range(0,n) if n<=10])
New guy here. I asked a while back about a sprite recolouring program that I was having difficulty with and got some great responses. Basically, I tried to write a program that would recolour pixels of all the pictures in a given folder from one given colour to another.
I believe I have it down, but, now the program is telling me that I have an invalid value specified for the red component of my colour. (ValueError: Invalid red value specified.), even though it's only being changed from 64 to 56. Any help on the matter would be appreciated!
(Here's the code, in case I messed up somewhere else; It's in Python):
import os
import media
import sys
def recolour(old, new, folder):
old_list = old.split(' ')
new_list = new.split(' ')
folder_location = os.path.join('C:\', 'Users', 'Owner', 'Spriting', folder)
for filename in os.listdir (folder):
current_file = media.load_picture(folder_location + '\\' + filename)
for pix in current_file:
if (media.get_red(pix) == int(old_list[0])) and \
(media.get_green(pix) == int(old_list[1])) and \
(media.get_blue(pix) == int(old_list[2])):
media.set_red(pix, new_list[0])
media.set_green(pix, new_list[1])
media.set_blue(pix, new_list[2])
media.save(pic)
if name == 'main':
while 1:
old = str(raw_input('Please insert the original RGB component, separated by a single space: '))
if old == 'quit':
sys.exit(0)
new = str(raw_input('Please insert the new RGB component, separated by a single space: '))
if new == 'quit':
sys.exit(0)
folder = str(raw_input('Please insert the name of the folder you wish to modify: '))
if folder == 'quit':
sys.exit(0)
else:
recolour(old, new, folder)
I'm coming from an XHTML/CSS background. I don't know much about JavaScript. Would you recommend learning JavaScript before learning a server programming language?
I want to filter some reserved word on my title form.
$adtitle = sanitize($_POST['title']);
$ignore = array('sale','buy','rent');
if(in_array($adtitle, $ignore)) {
$_SESSION['ignore_error'] = '<strong>'.$adtitle.'</strong> cannot be use as your title';
header('Location:/submit/');
exit;
How to make something like this. If
user type Car for sale the sale
will detected as reserved keyword.
Now my current code only detect single keyword only.