Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
kiwid
Sep 30, 2013

So, I've been tasked with putting a video on our website. Easy enough just using HTML5.

Here are the problems:
1. The video changes two to three times a day (kind of like a podcast but relating to our industry) and I don't want to be doing this manually.
2. I get the videos via FTP access which has access to all the videos in the root ftp folder, all named with no standard.
3. It does appear that I could use the date modified timestamp to show the latest video.

What is the best way to go about this?

kiwid fucked around with this message at 18:11 on Oct 21, 2014

Adbot
ADBOT LOVES YOU

kiwid
Sep 30, 2013

revmoo posted:

- Crontab shell script runs hourly and connects to FTP to check for new video based off timestamp. Store timestamp in a plain text file that the shell script can consult
- If it finds a video, copy it to webroot

If you just need the latest video then keep the file name the same and overwrite it and you're done. If you need to be able to show previous videos then you'll probably need to write a CLI php script that is triggered from the shell script that goes and does whatever database updates you need. This is all assuming your video codec is automatically HTML5-friendly and ready to post.

You'll need to do some homework to find a way to automate FTP via a shell script but it shouldn't be too hard to figure out.

Yeah I can definitely figure out the specifics. I just wanted to know the general flow of how you'd do it and this post just confirms essentially the way I was thinking of doing it in the first place. Luckily the video is HTML5-friendly so this should be as straight forward as you detailed.

McGlockenshire posted:

Well, there's ext/ftp, which you probably have installed already. You can use that to poke around and pull files down, but it'll be clunky.

Is PHP's built in FTP functionality the way to go or is there something like Guzzle but for FTP out there that is better?

kiwid fucked around with this message at 19:45 on Oct 21, 2014

kiwid
Sep 30, 2013

gently caress, so I tried to implement this tonight...

php:
<?
// connect to the ftp server
$conn = ftp_connect($server);
ftp_login($conn, $username, $password);
ftp_pasv($conn, true);

// get all mp4 files into an array with date modified timestamp
$data = [];
$files = ftp_nlist($conn, '');
foreach ($files as $file) {
    if (pathinfo($file, PATHINFO_EXTENSION) == 'mp4')
    {
        $data[$file] = ftp_mdtm($conn, $file);
    }
}

arsort($data, SORT_NUMERIC); // sort the array by date modified, newest first
$video_time = Settings::get('video_time'); // get the date modified of the last file downloaded

// foreach mp4 file, if file is newer or doesn't exist, download it
foreach ($data as $file => $time)
{
    if (($time > $video_time->value) || ( ! file_exists('video/video_comments.mp4')))
    {
        ftp_get($conn, 'video/video_comments.mp4', $file, FTP_BINARY);
        Settings::update('video_time', $time);
    }

    break; // only check the newest file
}

ftp_close($conn);
?>
I'm running into 504 gateway timeout issues (30seconds). Would that be because there is like 1000 video files among thousands of other types of files, like .jpg, .gif, etc. in the FTP directory?

edit: to be exact, there are 5997 files in this ftp directory + 10ish every day.

kiwid fucked around with this message at 02:52 on Oct 22, 2014

kiwid
Sep 30, 2013

McGlockenshire posted:

So, plan A: modification time won't be changing on these files, right? If so, it'll probably be safe to cache the result of the ftp_mdtm calls, which are probably what's sucking up all the run time.

Plan B: Run it by cron, no worries about hitting a gateway timeout that way, and you can just disable the execution time limit if need be.

Plan C: Hire a team of assassins to take out the idiots upstream responsible for the video delivery method and have it replaced with something sane that involves active notifications of new or changed content instead of having to index a few thousand things every time.

Definitely would like to go with Plan C. However, I'll give Plan A a try. Another option I was thinking was to use the ftp_rawlist command and parse the date/time from that. It's a bit messier but I can get a rawlist in 7 seconds, rather than timing out.

kiwid
Sep 30, 2013

Anyone know a good free/opensource Microsoft Access ODBC driver for Mac OS X and Linux?

This one costs $1000 http://www.easysoft.com/products/data_access/odbc-access-driver/index.html#section=tab-1

kiwid
Sep 30, 2013

I've been tasked to create an app that consolidates about 15 Microsoft Access databases (each of our robots logging data to each database in a standard format) into one database so that we can easily report off the data. Simple enough. However, my problem is that I don't know where to start on actually connecting to a Microsoft Access database. There are a bunch of ODBC drivers out there it seems but the problem is that I develop on OS X and deploy to a Debian or Ubuntu server so I need to purchase an ODBC driver for both platforms. Alternatively I could probably do something with Windows which has a free ODBC driver for Access. Otherwise, I was thinking I could have the Access databases dump to a CSV or something on a scheduled task?

Has anyone here ever had to do something like this and if so what is my best way going about it?

If this is too retarded for PHP, should I look into creating a python script that does this instead?

kiwid fucked around with this message at 17:20 on Jun 29, 2017

kiwid
Sep 30, 2013

Tad Naff posted:

When I had to work with Access databases and PHP I ended up converting them to MySQL using "mdbtools" I think it was called. I also had to edit the source of mdbtools to make its output actually MySQL compatible. As far as I know there's not much out there at least free that lets you connect to Access from PHP on Linux, but this was about eight or nine years ago, maybe things have improved since then.

I checked out mdbtools and it seems like a lot of work. I'm not Work isn't opposed to paying for something if it works. I found this after a bunch of Googling. I'm just going to set this up on a Windows desktop and dump to a MySQL database. I'm trailing it and it will dump multiple access databases to a single mysql database and then I'll just union the tables in PHP. I guess this is as good as it gets.

kiwid
Sep 30, 2013

ConanThe3rd posted:

So, I have a client who wants to take their Excell spreadsheet of ID Numbers and copy-paste it into a textfield to apply a status to it.

Currently I have explode() doing that but I'm not sure what character I use for a new row for excell, any help?

Can you get the format in CSV instead?

kiwid
Sep 30, 2013

I'm about to work with an external API that requires OAuth2. In the past I've always just opted for using API keys since most third party APIs offer alternatives and I didn't at the time want to dive down the rabbit hole of OAuth2. Anyway, the API I'll be working with is DocuSign and they require OAuth2.

My question is, how do you typically store the access tokens? Also, the DocuSign API documentation says that you can't refresh their tokens so you need to regenerate them when they expire but it appears to allow you to set the expiry time. What would be a good duration to expire these access tokens?

I'm working with the Laravel framework if it matters.

kiwid
Sep 30, 2013

I asked this on Laracasts but didn't get any replies. Hoping someone can help me here.

My question is: How do I read source code that eventually leads back to an interface?

Whenever I'm trying to figure out how something works and it leads back to an interface, I get lost.

For example, I was trying to figure out how the `Str::plural()` method works.

Step 1: Look up the `Illuminate\Support\Str` class.
Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Str.php

Step 2: Find the `plural()` method.
Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Str.php#L278-L281

Step 3: See that it's using a `Pluralizer` class so find that.
Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Pluralizer.php

Step 4: Find the `plural()` method on the `Pluralizer` class.
Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Pluralizer.php#L65-L74

Step 5: See that it's using Doctrine's Inflector class so find that.
Done: https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Inflector/Inflector.php

Step 6: Find the `pluralize()` method on the `Inflector` class.
Done: https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Inflector/Inflector.php#L502-L505

Step 7: See that it's calling an `inflect()` method on a `pluralizer` object so try to find what the `pluralizer` object is.
Done: It appears to be some type of instance of a `WordInflector` interface.

Now how do I go from here? I have no idea what the object is being passed that implements the `WordInflector` interface.

kiwid
Sep 30, 2013

Master_Odin posted:

The main problem here is the you're looking at the source code of the latest version of the Inflector which laravel does not use, which is why you can't find what the concrete WordInflector it's using. A quick look at it's composer.json reveals it has a ^1.1.0 dependency on the Inflector, so you could start there (or at 1.3, you'd have to look at the composer.lock file to get the exact version they're assuming).

Looking at the 1.3 release (though I'm not fully sure it uses this, or an older version still, you'd have to check) should make more sense: https://github.com/doctrine/inflector/blob/1.3.x/lib/Doctrine/Common/Inflector/Inflector.php

It should be noted that the new version of the Inflector that is being designed does not have static methods similar to the old version which would be a clue you weren't looking at the right code.

You're right I should have clued into the fact that Laravel was using a static method but knowing Laravel I figured it was using some obscure "magic" somewhere. My bad.

kiwid
Sep 30, 2013

This might be better off asked in the SQL/database threads but I'll try here first.

Let's say I've built a todo/task tracking application. I now want to add the ability to have scheduled or recurring tasks and I'm not sure how to model this in the database or how to implement this in the backend.

On the front end it would basically allow a user to do the following:

- Schedule a task into the future one time
- Repeat tasks every __ days
- Repeat a task every week on a specific day
- Repeat a task every month on a specific day or the first/second/etc day/week of the month

These are non-technical users so asking for a cron statement isn't going to work. How would I model this in the database and consume it?

kiwid
Sep 30, 2013

Tei posted:

I think you can do with something like this:
- record the last time the task was executed
- flags for whatever repetition types you need (make sense to allow to combine many types, like "every monday for 30 days")
- flag for completed (aka "stop any type of repeated execution")
- (optional) you may need some counters if your repetition is something like "repeat for 88 days"


Thanks, after looking into it further it looks like this is called RRULE and there are libs out there to make this easier: https://github.com/rlanvin/php-rrule

kiwid
Sep 30, 2013

I'm using Laravel and have to work with a database from another piece of software using a read-only connection to pull in various data.

I want to model some of the tables(views) so I can use eloquent relationships but the problem is that this database makes heavy usage of composite keys which eloquent doesn't support.

So I find myself doing poo poo like this where I concat all of the keys to one column. It's working... but I'm wondering if I'll run into any issues doing this that I'm not aware of.

SQL code:
        DB::statement(
            <<<SQL
                CREATE OR ALTER VIEW [mixers]
                AS
                SELECT
                    CONCAT_WS('-', LOWER([prd_mixer].[plc_id]), LOWER([prd_mixer].[mixer_id])) AS [id],
                    LOWER([prd_mixer].[plc_id]) AS [location_id],
                    [prd_mixer].[mixer_id] AS [name],
                    [prd_mixer].[description],
                    [prd_mixer].[mixer_size] AS [size],
                    [prd_mixer].[uom_code]
                FROM [{$agtech_database}].[dba].[prd_mixer] WITH (NOLOCK)
                WHERE [prd_mixer].[plc_id] IN ('seed', 'seed-palm');
            SQL
        );
SQL code:
        DB::statement(
            <<<SQL
                CREATE OR ALTER VIEW [batch_tickets]
                AS
                SELECT
                    CONCAT_WS('-', LOWER([prd_batch_ticket_entry].[plc_id]), [prd_batch_ticket_entry].[ticket_nbr]) AS [id],
                    LOWER([prd_batch_ticket_entry].[plc_id]) AS [location_id],
                    [prd_batch_ticket_entry].[ticket_nbr],
                    [prd_batch_ticket_entry].[revision_nbr],
                    [prd_batch_ticket_entry].[order_status],
                    [prd_batch_ticket_entry].[order_qty],
                    [prd_batch_ticket_entry].[order_uom],
                    [prd_batch_ticket_entry].[number_of_batches],
                    [prd_batch_ticket_entry].[comments],
                    [prd_batch_ticket_entry].[printed_flag],
                    [prd_batch_ticket_entry].[required_date],
                    [prd_batch_ticket_entry].[status_change_date],
                    LOWER([prd_batch_ticket_entry].[commodity_id]) AS [commodity_id],
                    CONCAT_WS('-', LOWER([prd_batch_ticket_entry].[plc_id]), LOWER([prd_batch_ticket_entry].[mixer_id])) AS [mixer_id],
                    CONCAT_WS('-', LOWER([prd_batch_ticket_entry].[plc_id]), LOWER([prd_batch_ticket_entry].[formula_id]), [prd_batch_ticket_entry].[revision_nbr]) AS [formula_id]
                FROM [{$agtech_database}].[dba].[prd_batch_ticket_entry] WITH (NOLOCK)
                WHERE [prd_batch_ticket_entry].[plc_id] IN ('seed', 'seed-palm');
            SQL
        );

kiwid
Sep 30, 2013

SpaceAceJase posted:

Is Laravel Livewire worth looking at? I tried a few demo apps hosted remotely and performance didn't seem great on a simple toggle switch

I love it, I use it in all my apps. As for performance, it's just Ajax behind the scenes so I'm not sure why you'd be having issues. I've used it on toggles that respond instantly.

kiwid
Sep 30, 2013

2Fast2Nutricious posted:

The regex you write to make sure you're not replacing multiple spaces in between characters would be a bit unwieldy, no?

Nah, easy with a positive lookbehind.

PHP code:
preg_replace('/(?<=[[:blank:]])[[:blank:]]+/', '', $string)
https://regex101.com/r/FMcUXb/4

Or if you don't want the leading space either:

PHP code:
preg_replace('/(?<=\s)\s+/', '', $string)
https://regex101.com/r/FMcUXb/5



kiwid fucked around with this message at 20:08 on Sep 27, 2023

kiwid
Sep 30, 2013

There is an open source package that I want to use to drastically reduce the manual work I'd need to do in my database queries. Unfortunately, the package only supports drivers for MySQL, Postgres, and SQLite and my application uses SQL Server. I see that there is a pull request on the repo that implements an SQL Server driver and commenters have confirmed it to be working but the PR has gotten no attention from the maintainer of the package for some reason.

I suspect the maintainer is just busy and will one day merge the PR but I can't wait for that. What is the best way to install the package with the SQL Server driver merged? Do I fork the repo, merge the PR, then install my forked repo until the maintainer one day merges it into his own or is there another way that I'm not thinking of?

kiwid
Sep 30, 2013

musclecoder posted:

then copy the code from the PR to your codebase until it's merged.

I hate doing this because the code would need to be in the vendor folder which I might forget about and accidentally wipe out.

duz posted:

If you're using composer to manage your dependencies, you can override a package with a version from a repo you set in the composer file.
https://getcomposer.org/doc/05-repositories.md#vcs

This worked perfectly.

kiwid
Sep 30, 2013

Anyone know a good video to teach me reflection? It's all magic to me and it's about time I learn how it actually works.

kiwid
Sep 30, 2013

Glimm posted:

Is there a preferred package for viewing Laravel logs as an admin on a site?

We're hosted in Azure, and viewing the logs through the Azure interface kinda stinks

Never used it but this is what Laravel Forge integrates with: https://www.papertrail.com/

Adbot
ADBOT LOVES YOU

kiwid
Sep 30, 2013

spiritual bypass posted:

No, but I'm curious where you need/want it

Was going to try building a simple framework to further my skills. Not actually to use.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply