Cannot submit the word in the textarea
I have a problem. when i write the word <script src=""></script> in the
textarea and submit to display the text, my web server doesn't allow to do
that. But i tested it with another web server it worked well. Can you tell
me what is the main problem? is it related to web server? how to deal with
it? here is the simple code I tested.
<form action="test.php" method="post">
<textarea name="txt"></textarea>
<input type="submit" name="btn" />
</form>
test.php
<?php
$text=$_POST['txt'];
echo htmlspecialchars($text);
?>
Thursday, 12 September 2013
Generating random variable from array based on weight percentage
Generating random variable from array based on weight percentage
I have the following code:
<?php
$gender = array(
'Male'=>30,
'Female'=>50,
'U' =>20);
$total = array_sum(array_values($gender));
$current = 0;
$rand = rand(1,$total);
foreach ($gender as $key=>$value)
{
$current += $value;
if ($current > $rand)
{
echo $key;
}
}
?>
However, when I run it, I sometimes get:
MaleFemaleU
Or:
FemaleU
I set the values for the $gender arrays, and would like to generate the
gender based on the percentage given, i.e. in this case: male 30, female
50, and unknown 20.
I have the following code:
<?php
$gender = array(
'Male'=>30,
'Female'=>50,
'U' =>20);
$total = array_sum(array_values($gender));
$current = 0;
$rand = rand(1,$total);
foreach ($gender as $key=>$value)
{
$current += $value;
if ($current > $rand)
{
echo $key;
}
}
?>
However, when I run it, I sometimes get:
MaleFemaleU
Or:
FemaleU
I set the values for the $gender arrays, and would like to generate the
gender based on the percentage given, i.e. in this case: male 30, female
50, and unknown 20.
Why am I seeing each class twice in my class view?
Why am I seeing each class twice in my class view?
I decided to give class view a go in VS2012 for some debugging work, but
for some reason every class appears twice. Double-clicking on either one
takes me to the declaration of the class, and selecting any of its methods
takes me to their definitions. So why are they there twice?
Note: "Cartcoord" only appears once, and as it's a template class it only
has a header file. The other classes, which are appearing twice, are all
.h/.cpp sets.
I decided to give class view a go in VS2012 for some debugging work, but
for some reason every class appears twice. Double-clicking on either one
takes me to the declaration of the class, and selecting any of its methods
takes me to their definitions. So why are they there twice?
Note: "Cartcoord" only appears once, and as it's a template class it only
has a header file. The other classes, which are appearing twice, are all
.h/.cpp sets.
Windows Phone adding eventhandler from different classes
Windows Phone adding eventhandler from different classes
Using this code, i am adding an eventhandler to the RootFrame.Obscured.
(Application.Current as App).RootFrame.Obscured += onObScured;
Since the RootFrame can be accessed from every class in the App, what
happens if i add different eventhandlers from different classes? Example:
class A{
(Application.Current as App).RootFrame.Obscured += onObScuredA;
private void onObScuredA(object sender, ObscuredEventArgs e) {
//Some code here
}
}
class B{
(Application.Current as App).RootFrame.Obscured += onObScuredB;
private void onObScuredB(object sender, ObscuredEventArgs e) {
//Some other code here
}
}
When the event is triggered, will both onObScuredA() and onObScuredB() be
triggered if there has been created an instance of both A and B? Is the
correct way, to add the eventhandlers, and their respective methods on the
App.xaml.cs class so i can be certain which eventhandlers are added?
Thanks.
Using this code, i am adding an eventhandler to the RootFrame.Obscured.
(Application.Current as App).RootFrame.Obscured += onObScured;
Since the RootFrame can be accessed from every class in the App, what
happens if i add different eventhandlers from different classes? Example:
class A{
(Application.Current as App).RootFrame.Obscured += onObScuredA;
private void onObScuredA(object sender, ObscuredEventArgs e) {
//Some code here
}
}
class B{
(Application.Current as App).RootFrame.Obscured += onObScuredB;
private void onObScuredB(object sender, ObscuredEventArgs e) {
//Some other code here
}
}
When the event is triggered, will both onObScuredA() and onObScuredB() be
triggered if there has been created an instance of both A and B? Is the
correct way, to add the eventhandlers, and their respective methods on the
App.xaml.cs class so i can be certain which eventhandlers are added?
Thanks.
Excluding word after dot "." in SQL
Excluding word after dot "." in SQL
Im using ms sql compact 4.0 for db and I just wanna ask How can I exclude
word after dot "." to add on my context-hint .
like for Example in my db: http://oi41.tinypic.com/2f06053.jpg
for TypeName "Indicators" , e.g in Indicators.RelativeStrengthIndex, i
only want the word "Indicators" to remain and delete word
".RelativeStrengthIndex" or after a dot . same as others .
DataExplorer://ObjDB.sdf/Table/[tb_CsType]
to be appear in my context-hint:
http://oi41.tinypic.com/2j5xczm.jpg
code for my autocomplete:
string conStr = @"Data Source=C:\Users\z\Desktop\Prot\DB\ObjDB.sdf";
SqlCeDataReader sqldrAllData;
SqlCeConnection sqlCon = new SqlCeConnection(conStr);
///1
SqlCeCommand sqlCmd = new SqlCeCommand("Select TypeName,
Syntax, Description From tb_CsType", sqlCon);
///2
//SqlCeCommand sqlCmd2 = new SqlCeCommand("Select
TypeName, Syntax, Description From tb_CsMember", sqlCon);
sqlCon.Open();
sqldrAllData = sqlCmd.ExecuteReader();
List<string> lstTypeName = new List<string>();
while (sqldrAllData.Read())
{
lstTypeName.Add(sqldrAllData["TypeName"].ToString());
}
foreach (var word in lstTypeName)
yield return (new Autoc(word) { ImageIndex = 3 });
sqlCon.Close();
then question was how can i exlude word after "." in my sql . thanks in
advance! more power!
Im using ms sql compact 4.0 for db and I just wanna ask How can I exclude
word after dot "." to add on my context-hint .
like for Example in my db: http://oi41.tinypic.com/2f06053.jpg
for TypeName "Indicators" , e.g in Indicators.RelativeStrengthIndex, i
only want the word "Indicators" to remain and delete word
".RelativeStrengthIndex" or after a dot . same as others .
DataExplorer://ObjDB.sdf/Table/[tb_CsType]
to be appear in my context-hint:
http://oi41.tinypic.com/2j5xczm.jpg
code for my autocomplete:
string conStr = @"Data Source=C:\Users\z\Desktop\Prot\DB\ObjDB.sdf";
SqlCeDataReader sqldrAllData;
SqlCeConnection sqlCon = new SqlCeConnection(conStr);
///1
SqlCeCommand sqlCmd = new SqlCeCommand("Select TypeName,
Syntax, Description From tb_CsType", sqlCon);
///2
//SqlCeCommand sqlCmd2 = new SqlCeCommand("Select
TypeName, Syntax, Description From tb_CsMember", sqlCon);
sqlCon.Open();
sqldrAllData = sqlCmd.ExecuteReader();
List<string> lstTypeName = new List<string>();
while (sqldrAllData.Read())
{
lstTypeName.Add(sqldrAllData["TypeName"].ToString());
}
foreach (var word in lstTypeName)
yield return (new Autoc(word) { ImageIndex = 3 });
sqlCon.Close();
then question was how can i exlude word after "." in my sql . thanks in
advance! more power!
Wednesday, 11 September 2013
Programmatic delivery of emails via SendGrid from PHP (bulk emails)
Programmatic delivery of emails via SendGrid from PHP (bulk emails)
We have been using SendGrid for some time for transactional email
delivery, however - we are starting to send bulk packages of email at
various intervals in an automated manner.
We are trying to find a way to send these bulk emails to sendgrid for
delivery instead of our current process (looping over a list of users and
sending the email iteratively)
Using something other than sendgrid is not an option
We need to basically have a way to upload a list of users, replacement
values for keywords in the email: %first_name%, %username% etc - in order
to send these emails to users.
What would be the best way to accomplish this?
We have been using SendGrid for some time for transactional email
delivery, however - we are starting to send bulk packages of email at
various intervals in an automated manner.
We are trying to find a way to send these bulk emails to sendgrid for
delivery instead of our current process (looping over a list of users and
sending the email iteratively)
Using something other than sendgrid is not an option
We need to basically have a way to upload a list of users, replacement
values for keywords in the email: %first_name%, %username% etc - in order
to send these emails to users.
What would be the best way to accomplish this?
How to wait for QureryCompleted event?
How to wait for QureryCompleted event?
I created a small application to get the Longitude and Latitude and to
convert it to actual address:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Device.Location;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Maps.Services;
using Microsoft.Phone.Shell;
using PhoneApp1.Resources;
using SunAngle;
using Windows.Devices.Geolocation;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
private GeoCoordinate Location;
public ObservableCollection<string> Addresses { get; set; }
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
protected override async void OnNavigatedTo( NavigationEventArgs e )
{
await GetLocation();
}
public async Task GetLocation()
{
Location = await CoordinateConverter.GetLocation();
ReverseGeoCoding.StartReverseGeoCoding( Location );
//ReverseGeoCoding.done.WaitOne();
string Address = ReverseGeoCoding.Address;
}
}
public static class ReverseGeoCoding
{
public static ObservableCollection<string> Addresses = new
ObservableCollection< string >();
public static string Address;
public static bool Completed;
public static AutoResetEvent done = new AutoResetEvent( true );
public static void StartReverseGeoCoding( GeoCoordinate Location )
{
Completed = false;
var reverseGeocode = new ReverseGeocodeQuery();
reverseGeocode.GeoCoordinate = new GeoCoordinate(
Location.Latitude, Location.Longitude );
reverseGeocode.QueryCompleted += ReverseGeocodeQueryCompleted;
done.Reset();
reverseGeocode.QueryAsync();
}
public static void ReverseGeocodeQueryCompleted( object sender,
QueryCompletedEventArgs<System.Collections.Generic.IList<MapLocation>>
e )
{
var reverseGeocode = sender as ReverseGeocodeQuery;
if ( reverseGeocode != null )
{
reverseGeocode.QueryCompleted -= ReverseGeocodeQueryCompleted;
}
//Microsoft.Phone.Maps.Services.MapAddress address;
Addresses.Clear();
if ( !e.Cancelled )
{
foreach ( var address in e.Result.Select( adrInfo =>
adrInfo.Information.Address ) )
{
Addresses.Add( string.Format( "{0} {1}, {2} {3} {4}, {5}",
address.HouseNumber,
address.Street,
address.City,
address.State,
address.PostalCode,
address.Country ).Trim() );
}
}
if ( Addresses.Count > 0 )
{
Address = Addresses[ 0 ].ToString();
}
else
{
Address = "";
}
done.Set();
Completed = true;
}
}
public static class CoordinateConverter
{
public static GeoCoordinate ConvertGeocoordinate( Geocoordinate
geocoordinate )
{
return new GeoCoordinate
(
geocoordinate.Latitude,
geocoordinate.Longitude,
geocoordinate.Altitude ?? Double.NaN,
geocoordinate.Accuracy,
geocoordinate.AltitudeAccuracy ?? Double.NaN,
geocoordinate.Speed ?? Double.NaN,
geocoordinate.Heading ?? Double.NaN
);
}
public static async Task<GeoCoordinate> GetLocation()
{
// Get current location.
Geolocator myGeolocator = new Geolocator();
myGeolocator.DesiredAccuracy = PositionAccuracy.High;
//myGeolocator.DesiredAccuracyInMeters = 50;
Geocoordinate myGeocoordinate = null;
try
{
Geoposition myGeoposition = await
myGeolocator.GetGeopositionAsync
(
maximumAge: TimeSpan.FromMinutes( 1 ),
timeout: TimeSpan.FromSeconds( 10 )
);
myGeocoordinate = myGeoposition.Coordinate;
}
catch ( Exception ex )
{
if ( (uint)ex.HResult == 0x80004004 )
{
// the application does not have the right capability or
the location master switch is off
MessageBox.Show( "location is disabled in phone settings" );
}
}
if ( myGeocoordinate == null )
{
return GeoCoordinate.Unknown;
}
GeoCoordinate myGeoCoordinate =
CoordinateConverter.ConvertGeocoordinate( myGeocoordinate );
return myGeoCoordinate;
}
}
}
The code works fine, i.e. the ReverseGeocodeQueryCompleted is called and
the address is being calculated properly. However,
ReverseGeocodeQueryCompleted occurs after GetLocation() is completed and
the address assigned to Address is null.
My question is how to make
ReverseGeoCoding.StartReverseGeoCoding( Location );
wait for the completion of the of:
ReverseGeocodeQueryCompleted( object sender,
QueryCompletedEventArgs<System.Collections.Generic.IList<MapLocation>> e )
{
....
}
I tried with AutoResetEvent and WaitOne, but the whole thread is stops and
the code never gets to ReverseGeocodeQueryCompleted().
I am open to suggestions how to solve this problem.
EitanB
I created a small application to get the Longitude and Latitude and to
convert it to actual address:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Device.Location;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Maps.Services;
using Microsoft.Phone.Shell;
using PhoneApp1.Resources;
using SunAngle;
using Windows.Devices.Geolocation;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
private GeoCoordinate Location;
public ObservableCollection<string> Addresses { get; set; }
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
protected override async void OnNavigatedTo( NavigationEventArgs e )
{
await GetLocation();
}
public async Task GetLocation()
{
Location = await CoordinateConverter.GetLocation();
ReverseGeoCoding.StartReverseGeoCoding( Location );
//ReverseGeoCoding.done.WaitOne();
string Address = ReverseGeoCoding.Address;
}
}
public static class ReverseGeoCoding
{
public static ObservableCollection<string> Addresses = new
ObservableCollection< string >();
public static string Address;
public static bool Completed;
public static AutoResetEvent done = new AutoResetEvent( true );
public static void StartReverseGeoCoding( GeoCoordinate Location )
{
Completed = false;
var reverseGeocode = new ReverseGeocodeQuery();
reverseGeocode.GeoCoordinate = new GeoCoordinate(
Location.Latitude, Location.Longitude );
reverseGeocode.QueryCompleted += ReverseGeocodeQueryCompleted;
done.Reset();
reverseGeocode.QueryAsync();
}
public static void ReverseGeocodeQueryCompleted( object sender,
QueryCompletedEventArgs<System.Collections.Generic.IList<MapLocation>>
e )
{
var reverseGeocode = sender as ReverseGeocodeQuery;
if ( reverseGeocode != null )
{
reverseGeocode.QueryCompleted -= ReverseGeocodeQueryCompleted;
}
//Microsoft.Phone.Maps.Services.MapAddress address;
Addresses.Clear();
if ( !e.Cancelled )
{
foreach ( var address in e.Result.Select( adrInfo =>
adrInfo.Information.Address ) )
{
Addresses.Add( string.Format( "{0} {1}, {2} {3} {4}, {5}",
address.HouseNumber,
address.Street,
address.City,
address.State,
address.PostalCode,
address.Country ).Trim() );
}
}
if ( Addresses.Count > 0 )
{
Address = Addresses[ 0 ].ToString();
}
else
{
Address = "";
}
done.Set();
Completed = true;
}
}
public static class CoordinateConverter
{
public static GeoCoordinate ConvertGeocoordinate( Geocoordinate
geocoordinate )
{
return new GeoCoordinate
(
geocoordinate.Latitude,
geocoordinate.Longitude,
geocoordinate.Altitude ?? Double.NaN,
geocoordinate.Accuracy,
geocoordinate.AltitudeAccuracy ?? Double.NaN,
geocoordinate.Speed ?? Double.NaN,
geocoordinate.Heading ?? Double.NaN
);
}
public static async Task<GeoCoordinate> GetLocation()
{
// Get current location.
Geolocator myGeolocator = new Geolocator();
myGeolocator.DesiredAccuracy = PositionAccuracy.High;
//myGeolocator.DesiredAccuracyInMeters = 50;
Geocoordinate myGeocoordinate = null;
try
{
Geoposition myGeoposition = await
myGeolocator.GetGeopositionAsync
(
maximumAge: TimeSpan.FromMinutes( 1 ),
timeout: TimeSpan.FromSeconds( 10 )
);
myGeocoordinate = myGeoposition.Coordinate;
}
catch ( Exception ex )
{
if ( (uint)ex.HResult == 0x80004004 )
{
// the application does not have the right capability or
the location master switch is off
MessageBox.Show( "location is disabled in phone settings" );
}
}
if ( myGeocoordinate == null )
{
return GeoCoordinate.Unknown;
}
GeoCoordinate myGeoCoordinate =
CoordinateConverter.ConvertGeocoordinate( myGeocoordinate );
return myGeoCoordinate;
}
}
}
The code works fine, i.e. the ReverseGeocodeQueryCompleted is called and
the address is being calculated properly. However,
ReverseGeocodeQueryCompleted occurs after GetLocation() is completed and
the address assigned to Address is null.
My question is how to make
ReverseGeoCoding.StartReverseGeoCoding( Location );
wait for the completion of the of:
ReverseGeocodeQueryCompleted( object sender,
QueryCompletedEventArgs<System.Collections.Generic.IList<MapLocation>> e )
{
....
}
I tried with AutoResetEvent and WaitOne, but the whole thread is stops and
the code never gets to ReverseGeocodeQueryCompleted().
I am open to suggestions how to solve this problem.
EitanB
Subscribe to:
Posts (Atom)