Using PHP I'd like to compare an actual ip address to part of one, and see if it matches.
For example I want to see if the address matches 12.34..
<?php
$rem_address = getenv('REMOTE_ADDR');
$temp = substr ($rem_address,0,6)
if ($temp == "12.34.") echo "It's a match";
?>
Is there an easier/better way to do this?
Hello,
I am trying to combine two integers in my application. By combine I mean stick one byte stream at the end of the other, not concatenate the strings.
The two integers are passed from hardware that can't pass a 32 bit value directly, but passes two consecutive 16-bit values separately.
Thanks,
Hi everyone,
I'm looking for a simple Flex or JavaScript based image editing component which can be embedded in a web application. It shouldn't be a web service but rather a component that I can download and customize (i18n etc.).
I only need some basic features: most important is cropping, optional features would be rotating and adjusting brightness/contrast.
Basically something like splashup.com, but as an open source application rather than a web-service.
Thanks a lot in advance for any hints!
-- Andreas
I have a variable that stores a Unix path, for example:
typeset unixpath=/foo/bar/
And I have to convert it to a DOS path using Korn shell scripting:
dospath=\\foo\\bar\\
I have a string like
def data = "session=234567893egshdjchasd&userId=12345673456&timeOut=1800000"
I want to convert it to a map
["session", 234567893egshdjchasd]
["userId", 12345673456]
["timeout", 1800000]
This is the current way I am doing it,
def map = [:]
data.splitEachLine("&"){
it.each{ x ->
def object = x.split("=")
map.put(object[0], object[1])
}
}
It works, but is there a more efficient way?
I'm trying to call the jQuery text() function and run it through the trim() function to remove all trailing and leading whitespace. Seems to work great in Firefox, however, does not work in IE7 (refuses to remove a space trailing at the end).
Any ideas?! Maybe a regex solution?
I'm dealing with a problem which needs to work with a lot of data. Currently its' values are represented as unsigned int. I know that real values do not exceed some limit, say 1000. That means that I can use unsigned short to store it. One profit is that it'll use less space. Do I have to pay for it by loosing in performance?
Another assumption. I decided to store data as short but all calling functions use int, so I need to convert between these datatypes when storing/extracting values. Wiil the performance lost be dramatic?
Third assumption. Due to great wish to econom memory I decided to use not short but just 10 bits packed into array of unsigned int. What will happen in this case comparing with previous ones?
i have several old, unused batches that i'm redoing.. I have a batch file for an old network
arch from several years ago..
the main thing I'd like it to do now is read a list of files.. I'll explain the setup..
Server updates a complete list [CurrentMediaStores.txt] 2x a day. The laptops can set settings to DL this list through their start.bat which also runs addins and updates I aply to my pc's, to give my batches and myself a break from slavish folder assignments and add a lil more dynamics and less adminin the bats now call on a list the user makes by simply copying a line from the CMS.txt file and pasting it into their [Grab_List.txt]
My problem is though I have the branch :: off right now and the code that detects if LAN is connected or not to switch to an ftp connection.
I'd like for the ftp batch to call/ use the Grab_List also. but I just can't/ don't know how to pass and do the for loop with a ftp session to loop through x amount of files in the users req list..
Anyhelp would be greatly appreciated
pt=[2]
pt[0]=raw_input()
when i do this , and give an input suppose 1011 , it says list indexing error- " list assignment index out of range" . may i know why? i think i am not able to assign a list properly . how to assign an array of 2 elements in python then?
"8,5,,1,4,7,,,,7,,1,9,3,6,,,8,6,3,9,,2,5,4,,,,,3,2,,,7,4,1,1,,4,,6,9,,5,,,,5,,,1,,6,3,,,6,5,,,,7,4,,1,7,6,,,,8,,5,,,7,1,,3,9,"
I'm doing a programming challenge where i need to parse this sequence into my sudoku script.
Need to get the above sequence into 8,5,0,1,4,7,0,0,0,7,0,1,9,3,6,0,0,8.........
I tried re but without success, help is appreciated, thanks.
Is it possible to show the list of items in a dropdown list when the user presses the up or down arrow keys, when focus is on that dropdown control? I think this would involve sending an onclick to the dropdown list using onkeydown for Keycode 38(arrow up) & 40(arrow down)? But I cannot figure out how to do this.
I resized an image using Java2D Graphics class. But it doesn't look right.
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
Is it possible to scale an image without introducing artifacts?
Good afternoon,
I'm learning about using RegEx's in Ruby, and have hit a point where I need some assistance.
I am trying to extract 0 to many URLs from a string.
This is the code I'm using:
sStrings = ["hello world: http://www.google.com", "There is only one url in this string http://yahoo.com . Did you get that?", "The first URL in this string is http://www.bing.com and the second is http://digg.com","This one is more complicated http://is.gd/12345 http://is.gd/4567?q=1", "This string contains no urls"]
sStrings.each do |s|
x = s.scan(/((http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.[\w-]*)?)/ix)
x.each do |url|
puts url
end
end
This is what is returned:
http://www.google.com
http
.google
nil
nil
http://yahoo.com
http
nil
nil
nil
http://www.bing.com
http
.bing
nil
nil
http://digg.com
http
nil
nil
nil
http://is.gd/12345
http
nil
/12345
nil
http://is.gd/4567
http
nil
/4567
nil
What is the best way to extract only the full URLs and not the parts of the RegEx?
Thanks
Jim
Yes/no-question: Is there a Groovy GDK function to capitalize the first character of a string?
I'm looking for a Groovy equivalent of Perl's ucfirst(..) or Apache Commons StringUtils.capitalize(str) (the latter capitalizes the first letter of all words in the input string).
I'm currently coding this by hand using ..
str = str[0].toUpperCase() + str[1 .. str.size() - 1]
.. which works, but I assume there is a more Groovy way to do it. I'd imagine ucfirst(..) being a more common operation than say center(..) which is a standard method in the Groovy GDK (see http://groovy.codehaus.org/groovy-jdk/java/lang/String.html).
I have this source code where I got it from net tutsplus. I have configured it and made it work in one PHP file. It does work by transferring the original image, but it does not generate to the thumbnails folder.
<?php
$final_width_of_image = 100;
$path_to_image_directory = "../../img/events/" . urldecode($_GET['name']) . "/";
$path_to_thumbs_directory = "../../img/events/" . urldecode($_GET['name']) . "/thumbnails/";
function createThumbnail($filename)
{
if(preg_match('/[.](jpg)$/', $filename))
{
$im = imagecreatefromjpeg($path_to_image_directory . $filename);
}
elseif(preg_match('/[.](gif)$/', $filename))
{
$im = imagecreatefromgif($path_to_image_directory . $filename);
}
elseif(preg_match('/[.](png)$/', $filename))
{
$im = imagecreatefrompng($path_to_image_directory . $filename);
}
$ox = imagesx($im);
$oy = imagesy($im);
$nx = $final_width_of_image;
$ny = floor($oy * ($final_width_of_image / $ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
imagejpeg($nm, $path_to_thumbs_directory . $filename);
$tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
echo $tn;
}
if(isset($_FILES['fupload'])) {
if(preg_match('/[.](jpg)|(gif)|(png)$/', $_FILES['fupload']['name'])) {
$filename = $_FILES['fupload']['name'];
$source = $_FILES['fupload']['tmp_name'];
$target = $path_to_image_directory . $filename;
move_uploaded_file($source, $target);
createThumbnail($filename);
}
}
?>
Basically it is supposed to generate a thumbnail of the uploaded image and store the original image into a different folder.
The paths are correct, it works by getting the folder name in the URL, it does work, but nothing works for the thumbnails folder.
BEFORE you ask this related question, yes, thumbnails generation does work on my server by the PHP GD, I have tested it separately. So this is not the problem. :)
How do I get this to work? :(
I was just checking an answer and realized that CHAR_BIT isn't defined by headers as I'd expect, not even by #include <bitset>, on newer GCC.
Do I really have to #include <climits> just to get the "functionality" of CHAR_BIT?
First of all, I'm not sure if solution even exists. I spent more than a couple of hours trying to come up with one, so beware.
The problem:
r1 contains an arbitrary integer, flags are not set according to its value. Set r0 to 1 if r1 is 0x80000000, to 0 otherwise, using only two instructions.
It's easy to do that in 3 instructions (there are many ways), however doing it in 2 seems very hard, and may very well be impossible.
I have a string that I would like represented uniquely as an integer.
For example: A3FJEI = 34950140
How would I go about writing a EncodeAsInteger(string) method. I understand that the amount of characters in the string will make the integer increase greatly, forcing the value to become a long, not an int.
Since I need the value to be an integer, I don't need the numerical representation to be entirely unique to the string.
Maybe I can foreach through all the characters of the string and sum the numerical keycode of the character.
I have a list, that has a custom content type, the list also contains subfolders
How can I add an item to the list using web services, in a specific sub folder?
How can I filter a string in c? I want to remove anything that isn't [a-z0-9_].
int main(int argc, char ** argv) {
char* name = argv[1];
// remove anything that isn't [a-z0-9_]
printf("%s", name);
}
Hi,
We're currently working out how to implement MVVM and I've got to the point where I've got the MVVM Light Toolkit set up in blend and can specify dummy data to be supplied if running in Blend. All good.
I've created a dummy list of data. The list contains 6 instances of a very simple class called DummyItem which has Age and Name properties.
Here's the main code from my 'DummyList' class:
public class DummyItem{
public string Name;
public int Age;
public DummyItem(string name, int age){
this.Name = name;
this.Age = age;
}
}
public class DummyList : ArrayList
{
public DummyList()
{
this.Add(new DummyItem("Dummy1", 00));
this.Add(new DummyItem("Dummy2", 01));
this.Add(new DummyItem("Dummy3", 02));
this.Add(new DummyItem("Dummy4", 03));
this.Add(new DummyItem("Dummy5", 04));
this.Add(new DummyItem("Dummy6", 05));
}
}
Here's the operative part of my XAML. The DataContext line does work and points to the correct ViewModel.
<Grid x:Name="LayoutRoot">
<ListBox x:Name="ListViewBox"
DataContext="{Binding Source={StaticResource Locator}, Path=ListViewModel}"
ItemsSource="{Binding TheList}"
DisplayMemberPath="Name">
</ListBox>
</Grid>
The problem is, when I add 'DisplayMemberPath', as I have above, then I can no longer see the list items in Blend. If I remove 'DisplayMemberPath', then I see a list of objects (DummyItem) with their full path. When the app is run, everything works perfectly. It's just that in Blend itself I cannot see the list items when I use 'DisplayMemberPath'.
Anyone know why I can't see the items inside Blend itself when I use DisplayMemberPath?
Thanks!
AT
In my bash script I have an external (received from user) string, which I should use in sed pattern.
REPLACE="<funny characters here>"
sed "s/KEYWORD/$REPLACE/g"
How can I escape the $REPLACE string so it would be safely accepted by sed as a literal replacement?
NOTE: The KEYWORD is a dumb substring with no matches etc. It is not supplied by user.
Hi,
I am looking for a regular expression for matching that contains no white space in between text but it may or may not have white space at start or end of text.