I need my program to create and edit a config file, which would contain information about set of objects, and than read it at every execution. Is there some sort of guideline for config style that i can use?
I would like the SO community let me know what does juniors and proficient .NET Developers should know regarding the following subjects, also some code examples or brainteasers like the ones here will help a lot.
System Types
Collection and Generics
Configuration and Installation
Monitoring and Debugging
File I/O
Globalization
Looking to have a database query set all the instance variables in a class:
Example:
def populate(self, if):
#Perform mysql query
self._name = row['name']
self._email = row['email']
...
What's the fastest way to do this? Or is this not recommended (with a better approach)?
Thanks.
Hi stackoverflow,
I apologize in advance for the possible stupidity of this question. However, the following has been the source of some confusion for me and I know the people here will be able to handily clear up the confusion for me. Basically, I would like to finally understand the relationship between any and all of the following terms. Some of the terms I do actually understand pretty well, but some of them are similar in my mind and I would like to once and for all to see their relationships/distinctions laid out all at once. They are:
compiler
interpreter
bytecode
machine code
assembler
assembly language
binary
object code
executable
Ideally, an answer would use examples from Java and C++ and other well-known programming languages that a young-ish student like me would be familiar with. Also, if you want to throw in any other useful terms that would be fine too :)
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.
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've made a page that uses jQuery to allow you to place <div>s on the page based on your mouse coordinates when you click.
The page
And here's the javascript:
$('document').ready(function() {
$("#canvas").click(function(e){
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
$(document.createElement('div')).css({'left':x + 'px', 'top':y + 'px'}).addClass('tile').appendTo('#canvas');
});
});
I've found that if you mousedown in the div#canvas and mouseup with your pointer over a placed <div> (or vice versa) then a new <div> doesn't get placed. Why is this?
Hi all,
I'd like to use a JS regex to take a string such as the following:
'http://www.somedomain.com/some_directory/some_other_directory/some_image.jpg'
And turn it into this:
'http://www.some_other_domain.com/another_directory/yet_another_directory/size1_some_image.jpg'
Any hints? Additionally, any pointers for books or other resources that give a gentle introduction to mastering regexes in JS and other languages?
I'm new at php and mysql stuff and i'm trying to use an avg function but i don't know how to.
I'm trying to do something like this:
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die ("Did not connect to $database");
mysql_query("AVG(column1) FROM table1 ") or die(mysql_error());
mysql_close();
echo AVG(column1);
(Q1)I'd like to see the value printed in the screen, but i'm getting nothing but an error message. How could I print this average on the screen ?
(Q2)If I had a column month in my table1, how could I print the averages by the months ?
Sorry for any bad English, and thanks for the attention.
What does the word "literal" mean when used in context such as literal strings and literal values? what is the difference between a literal value and value?
Normally is use
$(document).ready(function() {
// do something
});
to do something after dom is loaded.
in the last time i often see
$(function() {
// do something
});
that also works. whats the difference?
Hi all.
Got some trouble with my preg_match.
The code.
$text = 'tel: 012 213 123. mobil: 0303 11234';
$regex_string = '/(tel|Tel|TEL)[\s|:]+(.+)[\.|\n]/';
preg_match($regex_string , $text, $match);
And I get this result in $match[2]
"012 213 123. mobil: 023 123 123"
First question.
I want the regex to stop at the .(dot) but it doesent.
Can someone explain to why it isnt?
Second question.
preg_match uses () to get their match.
Is it possible to skip the parentheses surrounding the different "Tel" and still get the same functionality?
Thnx all stackoverflow is great :D
I am adapting the Coverflow technique to work with a div. The coverflow function (included as a js file in the head section) is here. When I dynamically add a DIV, it doesn't show up in the coverflow. I am wondering if there is a way to add a destroy function to this js file so that whenever a new div add is added, I can call the destroy method and then reinstantiate. Any suggestions on how I should go about doing this?
Say i have these classes
ViewA and ViewB
In objective C using the delegate pattern I could do
@protocol ViewBDelegate{
- (void) doSomething();
}
then in ViewB interface:
id<ViewBDelegate> delegate;
then in ViewA implementation i set the delegate:
viewB.delegate = self;
and now I can call in doSomething from viewB onto any that unknown type delegate.
[delegate doSomething];
"C++ How to Program" has been the worse read an can't find simple examples that demonstrates basic design patterns.
What i'm looking for in C++ is:
events ActionScript and java
either delegates or notifications in Objective C
anything that allows class A, Class B and Class C to know that ClassX
didSomething()!!!
thanks
I know charwise positions of matches like 1 3 7 8. I need to know their corresponding line number.
Example: file.txt
Match: X
Mathes: 1 3 7 8.
Want: 1 2 4 4
$ cat file.txt
X2
X
4
56XX
[Added: does not notice many linewise matches, there is probably easier way to do it with stacks]
$ java testt
1
2
4
$ cat testt.java
import java.io.*;
import java.util.*;
public class testt {
public static String data ="X2\nX\n4\n56XX";
public static String[] ar = data.split("\n");
public static void main(String[] args){
HashSet<Integer> hs = new HashSet<Integer>();
Integer numb = 1;
for(String s : ar){
if(s.contains("X")){
hs.add(numb);
numb++;
}else{
numb++;
}
}
for (Integer i : hs){
System.out.println(i);
}
}
}
Which is the best practice in this situation? I would like an un-initialized array of the same type and length as the original.
public static <AnyType extends Comparable<? super AnyType>> void someFunction(AnyType[] someArray) {
AnyType[] anotherArray = (AnyType[]) new Comparable[someArray.length];
...or...
AnyType[] anotherArray = (AnyType[]) new Object[someArray.length];
...some other code...
}
Thanks,
CB
i am reading a csv file and i want to store this in datastore, but i am getting string from file for datetime field.
i want to type cast it to datetime
also same for date and time separately
error::BadValueError: Property HB_Create_Ship_Date must be a datetime
I have the follwing C function. How should I wrap it so it can be called from a Lua script?
typedef struct tagT{
int a ;
int b ;
} type_t;
int lib_a_f_4(type_t *t)
{
return t->a * t->b ;
}
I know how to wrapr it if the function parameter type were int or char *. Should I use table type for a C structure?
EDIT: I am using SWIG for the wraping , according to this doc, It seems that I should automatically have this funtion new_type_t(2,3) , but it is not the case.
If you wrap a C structure, it is also
mapped to a Lua userdata. By adding a
metatable to the userdata, this
provides a very natural interface. For
example,
struct Point{ int x,y; };
is used as follows:
p=example.new_Point()
p.x=3
p.y=5
print(p.x,p.y) 3 5
Similar access is provided for unions
and the data members of C++ classes. C
structures are created using a
function new_Point(), but for C++
classes are created using just the
name Point().
Hey I'm wondering how i can get this code to work, basically i want to keep the lines of $filename as long as they contain the $user in the path. Sry, perl noob.
open STDERR, ">/dev/null";
$filename=`find -H /home | grep $file`;
@filenames = split(/\n/, $filename);
for $i (@filenames) {
if ($i =~ m/$user/) {
#keep results
} else {
delete $i; # does not work.
}
}
$filename = join ("\n", @filenames);
close STDERR;
I know you can delete like delete $array[index] but I don't have an index with this kind of loop that I know of.