PHP timezone not set - timezone

First of all, i don't have access to the php.ini in the webserver.
In my local server I put date.timezone = "Europe/Lisbon" in my php.ini.
Is it possible to change this in .htaccess? or, what is the alternative?
At the moment I get this error in web server for phpmailer():
Strict Standards: date(): It is not safe to rely on the system's timezone settings. ....

On second thought, ini_set may not be the best way to go. Apparently E_STRICT standards say that you should use date_default_timezone_set instead.
Try something like:
date_default_timezone_set('Europe/Lisbon');
$tz = date_default_timezone_get();
More info can be found here about the issue:
http://answers.google.com/answers/threadview/id/739376.html
And here for the default_timezone functions:
http://us2.php.net/manual/en/function.date-default-timezone-set.php
Edit: I found this little gem while I was browsing github.
// has to be set to reach E_STRICT compatibility, does not affect system/app settings
date_default_timezone_set(date_default_timezone_get());
This seems like the best solution.

Try ini_set at the top of your script.
ini_set("date.timezone", "Europe/Lisbon");

Your problem is not difficult. You can change date.timezone in the php.ini and delete => ; <= is the comment in the php.ini
for example
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone =Europe/Paris
http://www.commentcamarche.net/forum/affich-14406518-probleme-avec-l-heure-en-php

Related

Can I force applications to run in a different locale to the system setting?

I am developing a C# .NET 6 client-server product using VS2022 with multi-language support. I've set up locale-specific resource strings but at the last minute I realized a problem: while client workstations are set up in local language, the app-server is always in English - so back-end code is using the English localization!
Servers are in English for a good reason (and we can't change this) so is there a way to force a deployed application to use a specified locale? Perhaps in a config file somewhere?
I know I can do this in code by changing Thread.CurrentCulture or similar, but the whole point is I don't want to hard-code it, I want it to be config-driven in a way that overrides the default system setting.
I want it to be config-driven in a way that overrides the default system setting.
You can always add custom setting to your config file and then read it on start up and set needed culture.
For example something like this:
appsettings.json
{
"LocaleOverride" : "en-US",
// rest of settings
}
And somewhere at the start of app (depends on how it is started, if generic/minimal hosting is used, configuration can be read from there, otherwise - manually):
var locale = Configuration["LocaleOverride"];
if(!string.IsNullOrEmpty(locale))
{
var cultureInfo = new CultureInfo(locale);
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
}

Getting the API_KEY from SendGrid .env file (Node.js)

I'm using SendGrid(Node.js) for one of my personal projects. I followed the integration guide to set up my API KEY .env file as following:
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
My question is... Every time before running the backend locally, I have to first run
source ./sendgrid.env
In order for the process.env.YOUR_API_KEY be acknowledged where the key is.
But after renamed the sendgrid.env file to just .env, I don't have to run source anymore.
This is how I call the API KEY
require('dotenv').config()
const { validationResult } = require('express-validator')
const Appointment = require('../models/Appointment')
const User = require('../models/User')
const sgMail = require('#sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
PS. I have set the dotenv config at the top of the file but still getting undefined until I changed the file name.
Does anyone know the reason or the logic behind this??
Thank you :)
If I am understanding it well enough. You have to change it to .env because by default require('dotenv').config() point to .env because the parenthesis of config are empty.
To follow the sendgrid way by calling your file sendgrid.env you would have to require('dotenv').config(sendgrid.env) and maybe, just require('dotenv').config(sendgrid) would be enough. Got to try it to know for sure. But at least from my understanding this is your answer.

How to use HMAC in Lua - Lightroom plugin

First thing I have to mention is I'm really really new to Lua and please be patient if you think my question is too dumb
Here is my requirement
I need to use HMAC-sha256 for Lightroom plugin development as I'm using that for security.
I was trying to use this but with no luck
https://code.google.com/p/lua-files/wiki/hmac
These are the steps I followed
Got the code of
https://code.google.com/p/lua-files/source/browse/hmac.lua and saved
as 'hmac.lua' file in my plugin directory
Got the code from this
https://code.google.com/p/lua-files/source/browse/sha2.lua and saved
as 'sha2.lua' file
Now in the file I use it like this
local hmac = require'hmac'
local sha2 = require'sha2'
--somewhere doend the line inside a function
local hashvalue = hmac.sha2('key', 'message')
but unfortunately this does not work and I'm not sure what I'm doing wrong.
Can anyone advice me what I'm doing wrong here? Or is there an easier and better way of doing this with a good example.
EDIT:
I'm doing this to get the result. When I include that code the plugin does stops working. I cannot get the output string when I do this
hashvalue = hmac.sha2('key', 'message')
local LrLogger = import 'LrLogger'
myLogger = LrLogger('FlaggedFiles')
myLogger:enable("logfile")
myLogger:trace ("=========================================\n")
myLogger:trace ('Winter is coming, ' .. hashvalue)
myLogger:trace ("=========================================\n")
and the Lightroom refuses to load the plugin and there is nothing on the log as well
Thank you very much for your help
I'd first make sure your code works outside of Lightroom. It seems that HMAC module you referenced has some other dependencies: it requires "glue", "bit", and "ffi" modules. Of these, bit and ffi are binary modules and I'm not sure you will be able to load them into Lightroom (unless they are already available there). In any case, you probably won't be able to make it run in LR if you don't have required modules and can't make it run without issues outside of LR.
If you just need to get SHA256 hash there is a way to do it Lightroom
I posted my question here and was able to get an answer. But there there was no reference of this on SDK documentation (Lightroom SDK)
local sha = import 'LrDigest'
d = sha.SHA256.digest ("Hello world")
but unfortunately there was no HMAC so I decided to use md5 with a salt because this was taking too much of my time
Spent quite some time trying to find a solution :-/
LrDigest is not documented, thanks Adobe!
Solution:
local LrDigest = import "LrDigest"
LrDigest.HMAC.digest(string, 'SHA256', key)

Iconv.conv in Rails application to convert from unicode to ASCII//translit

We wanted to convert a unicode string in Slovak language into plain ASCII (without accents/carons) That is to do: č->c š->s á->a é->e etc.
We tried:
cstr = Iconv.conv('us-ascii//translit', 'utf-8', a_unicode_string)
It was working on one system (Mac) and was not working on the other (Ubuntu) where it was giving '?' for accented characters after conversion.
Problem: iconv was using LANG/LC_ALL variables. I do not know why, when the encodings are known, but well... You had to set the locale variables to something.utf8, for example: sk_SK.utf8 or en_GB.utf8
Next step was to try to set ENV['LANG'] and ENV['LC_ALL'] in config/application.rb. This was ignored by Iconv in ruby.
Another try was to use global system setting in /etc/default/locale - this worked in command line, but not for Rails application. Reason: apache has its own environment. Therefore the final solution was to add LANG/LC_ALL variables into /etc/apache2/envvars:
export LC_ALL="en_GB.utf8"
export LANG="en_GB.utf8"
export LANGUAGE="en_GB.utf8"
Restarted apache and it worked.
This is more a little how-to than a question. However, if someone has better solution I would like to know about it.
You can try unaccent approach instead.

how to delete rails log file after certain size

I have a daemon that runs constantly which fills up the log file(development.log or production.log) pretty quickly. What is the best way to delete the log file after certain size or delete the portion before certain day.
config.logger = Logger.new(config.log_path, 50, 1.megabyte)
but beware that multiple mongrels can have issues with this.
The best way is to set up log rotation, but how you do this is very platform dependent,
so you should add a comment about what you're using, both for development and production.
For our apps running on Linux, we have a file /etc/logrotate.d/appname for each app,
that looks something like this:
/path/to/rails_root_for_app/log/production.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
create 640 capistrano capistrano
}
This will move the log into a new file once a day, keeping a compressed backup file for each
of the last 7 days.
If you just want to empty the file without keeping any of the data in it while the daemon is
running, simply do this from a shell:
> /path/to/rails_root_for_app/log/development.log
This will truncate the file to 0 bytes length.
I prefer a monthly log file in my production.rb file
config.logger = Logger.new(config.log_path, 'monthly')
Or even better, if all your environments are on either Mac or Linux, and have /usr/sbin/rotatelogs, just use that. It's much more flexible, and doesn't have the data loss issue that logrotate has (even if you use copytruncate).
Add this inside config/application.rb (or just config/environments/production.rb if you only want rotation in prod):
log_pipe = IO.popen("/usr/sbin/rotatelogs #{Rails.root}/log/#{Rails.env}.%Y%m%d.log 86400", 'a')
config.logger = Logger.new(log_pipe)
(From this blog post)
Or you can delegate logging to syslog

Resources