This is related to the PHP framework YII. If you are trying to generate a file (let's say, a controller), and get the error message "Unable to write file...", then simply change the permissions of the entire web folder, of course, provided this is in a secure development environment.
sudo chmod -R 777 /path/to/your/webapp_folder_name
2013-08-30
2013-08-29
PHP - "It is not safe to rely on the system's timezone settings..."
If you get an error message like the one below, simply add this line to your php.ini file.
date.timezone = "America/New_York"
date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead
date.timezone = "America/New_York"
date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead
APACHE - How to start, stop or restart the apache server
Just type this command in a new Terminal window:
Restart:
Stop:
Start:
Restart:
sudo apachectl restart
Stop:
sudo apachectl -k stop
Start:
sudo apachectl -k start
PHP - How to get local server's PHP configuration
Create a .php docuemnt within the server, with the following content, then simply open it. The web file will display the location of the php.ini file and every parameter related to PHP's settings in the server.
phpinfo();
?>
phpinfo();
?>
2013-08-08
TSQL - Function to transform a given comma-separated string value into a table with one row per element
Execution example:
getTableFromCSV('asdf,qwer,poiu');
Funcion's code:
getTableFromCSV('asdf,qwer,poiu');
Funcion's code:
ALTER function [dbo].[getTableFromCSV]
(
@csv VARCHAR(MAX)
)
RETURNS
@tbl TABLE( val VARCHAR(255) )
AS
BEGIN
DECLARE @sTemp VARCHAR(255)
WHILE LEN(@csv) > 0
BEGIN
SET @sTemp = LEFT(@csv, ISNULL(NULLIF(CHARINDEX(',', @csv) - 1, -1), LEN(@csv)))
SET @csv = SUBSTRING(@csv,ISNULL(NULLIF(CHARINDEX(',', @csv), 0), LEN(@csv)) + 1, LEN(@csv))
INSERT INTO @tbl VALUES (LTRIM(RTRIM(@sTemp)))
END
-- kill the nulls/ empty strings
DELETE FROM @tbl WHERE val IS NULL OR val = ''
RETURN
END
;
TSQL - Function to get string returned as a table with one record for each word, and some basic stats
If you create the function (code below), and execute this:
select * from getWords( 'this is only a
one one figurative test test ', 0, 1 );
You will get this:
The function's code:
create FUNCTION [dbo].[getWords]
(
@text nvarchar(4000)
, @ReturnOnlyMeaningful
bit
, @SuppressDuplicates
bit
)
RETURNS
@words
TABLE (
WordID smallint --primary key
--, Position smallint
, Word varchar(255)
, OrderOfAppearance tinyint
, AlphabeticRank tinyint
, [Length] tinyint
, LengthRank tinyint
, Frequency tinyint
, WordCount tinyint
, DistinctWordCount tinyint
, Meaningful tinyint
, MeaningfulWordCount
tinyint
, MeaningfulDistinctWordCount
tinyint
, OriginalText varchar(4000)
)
AS
BEGIN
-- Parameter validation and cleanup
-- Do not process empty strings
if ltrim(rtrim(@text)) = ''
begin
return
end
-- Double quote characters if found
/*
select
REPLACE( 'this is" something', '"', '""' );
select
REPLACE( 'this is'' something', '''', '''''' );
*/
set @text = REPLACE( @text, '"', '""' );
set @text = REPLACE( @text, '''', '''''' );
-- If it is ok to display dupicates
if @SuppressDuplicates
= 0
begin
insert into
@words
select
occurrence
, display_term
, dense_rank()
over(
order by occurrence asc
)
as OrderOfAppearance
, DENSE_RANK()
over(
order by display_term asc
) as AlphabeticRank
, LEN( display_term ) as [Length]
, dense_rank()
over(
/*
partition
by
case
when
special_term = 'Exact Match'
then
1
else
0
end
*/
order by LEN( display_term ) desc
) as isMeaningfulLengthRank
, CAST( 1 as tinyint ) as Frequency
, null as WordCount
, null as DistinctWordCount
, cast(
case
when special_term = 'Exact Match'
then 1
else 0
end
as tinyint
) as isMeaningful
, null as MeaningfulWordCount
, null as MeaningfulDistinctWordCount
, @text as OriginalText
from
sys.dm_fts_parser ( N'"' + @text + '"', 1033, 0, 0)
where
-- Return only meaningful, according to the parameter
(
@ReturnOnlyMeaningful =
0
or (
@ReturnOnlyMeaningful =
1
and special_term = 'Exact Match'
)
)
-- Do not return end of file word.
and display_term not in
(
'END OF FILE' -- Seems to be
produced by hyphens
)
;
end
-- If we are to suppress duplicates
else
begin
insert into
@words
select
min( occurrence ) as occurrenceMin
, display_term
, dense_rank()
over(
order by min( occurrence ) asc
)
as OrderOfAppearance
, DENSE_RANK()
over(
order by display_term asc
) as AlphabeticRank
, LEN( display_term ) as [Length]
, dense_rank()
over(
/*
partition
by
case
when
special_term = 'Exact Match'
then
1
else
0
end
*/
order by LEN( display_term ) desc
) as isMeaningfulLengthRank
, COUNT(*) as Frequency
, null as WordCount
, null as DistinctWordCount
, cast(
case
when special_term = 'Exact Match'
then 1
else 0
end
as tinyint
) as isMeaningful
, null as MeaningfulWordCount
, null as MeaningfulDistinctWordCount
, @text as OriginalText
from
sys.dm_fts_parser ( N'"' + @text + '"', 1033, 0, 0 )
where
-- Return only meaningful, according to the parameter
(
@ReturnOnlyMeaningful =
0
or (
@ReturnOnlyMeaningful =
1
and special_term = 'Exact Match'
)
)
-- Do not return end of file word.
and display_term not in
(
'END OF FILE'
)
group by
display_term
, case
when special_term = 'Exact Match'
then 1
else 0
end
;
end
-- Word count
update
@words
set
WordCount = ( select SUM(Frequency) from @words )
, DistinctWordCount = ( select COUNT(*) from @words )
, MeaningfulWordCount
= ( select SUM( Meaningful * Frequency ) from @words )
, MeaningfulDistinctWordCount
= ( select SUM( Meaningful ) from @words )
;
-- Return
return;
end
TSQL - Text field into table with one row per word
SQL Server 2012...
select * from sys.dm_fts_parser ( '"this is a-long text file file"', 1033, 0, 0 );
For more details, read
http://technet.microsoft.com/en-us/library/cc280463.aspx
select * from sys.dm_fts_parser ( '"this is a-long text file file"', 1033, 0, 0 );
For more details, read
http://technet.microsoft.com/en-us/library/cc280463.aspx
Subscribe to:
Posts (Atom)