ohffs

Experience

255,430

281 Best Reply Awards

  • Member Since 3 Years Ago
  • 955 Lessons Completed
  • 2 Favorites

23rd September, 2018

ohffs left a reply on Getting Involved • 1 hour ago

It's often said - but contributing bug fixes and documentation to projects can be a great 'way in' and lets you get experience delving further into projects that you'd otherwise just 'consume'.

If there are any packages you use a lot - have a look at their github pages and check out the 'Issues' and see if there's anything that you could help with - or if you've used a package and spent time figuring out how some aspect worked that wasn't mentioned in the docs - try making a request to add some helpful docs.

Or even just write a blog post about 'how to do X with package Y' - some day someone will be looking for it on google and you'll save them hours of frustration :-) Same goes for replying to github issues - if you can post a reply for someone who is trying to figure out something you've already done you can help everyone in the future trying to do the same thing.

(I've actually found myself googling for a problem and found a reply I'd posted to github where I'd fixed the exact issue - just totally forgotten it - I buy myself a beer to thank myself ;-)

There's also Hacktoberfest coming up - which can be a really nice place to find projects that need help :-)

[And just to join in the somewhat OT complaints about the search - yeah, it is pretty difficult to use. Very slick visually, but quite hard to find anything of use. I've actually been using the forum way, way less since the last re-design due to the 'mentions' bug as the only way to see if I've had any replies/mentions is to go in manually and check the times on any questions - which is a bit annoying really. Hopefully the new redesign will fix some of this though :-)]

22nd September, 2018

ohffs left a reply on API/Passport Series? • 23 hours ago

@Loach the search on the site only shows one course specifically about passport? And it seems to just be the regular oauth login flow rather than anything about running your own API with multiple types of consumer?

ohffs left a reply on Connected PlayStations • 1 day ago

Maybe either give them fixed IP addresses and use a ping to check if they are online, or possibly make a call to arp -a to see what MAC addresses are showing up on your network. Then when an IP or MAC appears or goes away you can update your application.

ohffs left a reply on API/Passport Series? • 1 day ago

Oops - didn't mean to mark your answer as the 'right' one (clumsy mouse-click!), @D9705996 - but have some points anway ;-)

21st September, 2018

ohffs left a reply on API/Passport Series? • 1 day ago

@D9705996 yeah - I've read quite a few blogs that are covering the straight-forward use-case - I guess I'm more interested in the uncommon use-cases ;-)

Maybe the problem is that passport is a huge package - but there's very, very little out there about using it in real life beyond 'now you can log in! woo - we're done!' ;-)

My API will be consumed by 'local' users (in a traditional laravel sense), external 'SPA' users and there will also be pure machine-to-machine consumers. Figuring out the mix of middlewares, terms etc is not very clear - so that's why I put in the series request :-)

ohffs started a new conversation API/Passport Series? • 1 day ago

I'm sure this must have been asked before - but my searches are mostly turning up questions about API's - so sorry if I'm the 100th person to ask ;-)

I guess a lot of us are ending up with more Hybrid/SPA type codebases and it'd be really nice to have a series - even something like the recent Relationships one - that went through some of the terminology, some ways to handle auth, dealing with ye olde fashioned 'session' data etc.

Selfish self-interested disclosure - I'm currently working on a site that will have a 'local' API (ie, users log into the site and get blade views etc - but those in turn fetch data from the local API - mostly as a dog-fooding exercise) - but with a second sister application which will work only via the API. Trying to get my head around the terms, passport middlewares etc has been a bit trial-and-error to say the least ;-)

Anyway - it'd be much appreciated by this befuddled old dev anyway :-)

ohffs left a reply on Small Topic For You How Do You Deploy Your Laravel Applications? • 1 day ago

I use Deployer at the moment - though I'm getting close to a working docker/kubernetes/container deployment path.

10th September, 2018

ohffs left a reply on Replacing A Large Array • 1 week ago

@bobbybouwmann localStorage can only store strings, sadly :-/

8th September, 2018

ohffs left a reply on DUSK Failed To Match PCRE Pattern [L5.5] • 2 weeks ago

Not sure - I usually use assertRouteIs if I'm checking - so not sure if something changed on assertPathIs. Does your APP_URL have a trailing slash maybe? Can't remember if that's used by dusk or not for these things though.

ohffs left a reply on DUSK Failed To Match PCRE Pattern [L5.5] • 2 weeks ago

What is the URL your controller is returning? Maybe there's an extra slash in there?

ohffs left a reply on DUSK Failed To Match PCRE Pattern [L5.5] • 2 weeks ago

Is it maybe just the assertPathIs("/ making it have the double-slash? Try asserting the path without the leading slash?

ohffs left a reply on Replacing A Large Array • 2 weeks ago

@bobbybouwmann it's not a huge amount of data - just about 2000 objects with about 10 plain string/int/bool fields in each (it's a live view of torrents downloading). I think it's possibly related to the caching of them in localStorage. I'm doing a JSON.stringify on the array to store it and then JSON.parse to get it back - which discards vue's magic watcher/getter/setter info - so it's possibly getting confused when the replacement objects go over the top of them.

It's not a big issue - just feels a little 'hacky' to have to do it like this.

7th September, 2018

ohffs left a reply on Replacing A Large Array • 2 weeks ago

@ouhare didn't think of that - I'll give it a try :-)

@bobbybouwmann the data isn't replaced often - just once about 10s after page load. The update never properly happens - even several minutes of clicking around later - so I don't think it's just my impatience :-) I think it's something to do with the way it replaces an array :

You might think this will cause Vue to throw away the existing DOM and re-render the entire list - luckily, that is not the case. Vue implements some smart heuristics to maximize DOM element reuse, so replacing an array with another array containing overlapping objects is a very efficient operation.

ohffs started a new conversation Replacing A Large Array • 2 weeks ago

Another in my 'bored on a Friday' series of questions. I was playing around with a little bit of code I have that has a large array of objects in the data() of the component. It loads the data from localStorage on page load and goes off to fetch the current data from an API - basically to give you something to look at as the API call takes about 10 seconds.

However, if I just do :

let newArray = await apiCall();
this.myData = newArray;

then this.myData doesn't seem to get properly replaced. The new data is there, but it's almost like it's a 'shadow'. So for instance you can click an item and it toggles a selected state - but after the api call you need to click the item twice before it 'notices' that it's clicked.

But, if I do :

let newArray = await apiCall();
this.myData = [];
this.$nextTick(() => {
      this.myData = newArray;
});

then it works perfectly. As far as I know Vue should notice that the array has been replaced so the first version should work - so I'm not sure why the second version is needed (I only tried it out of desperation).

Anyone come across this before? I'm guessing it's something to do with the way Vue tries to merge the state of the items.

6th September, 2018

ohffs left a reply on Ajax Table Editing • 2 weeks ago

Handson Table might also be worth a look.

4th September, 2018

ohffs left a reply on Calling Mysqldump Via Route Returning An Empty Sql • 2 weeks ago

What did the $returnVar have in it? Do you get anything in the $output variable? It's hard to know what's happening - there could be a lot of causes - your web version php might not have permission to run exec even.

You could also - once you've checked $returnVar & $output - try doing a dd($command) just to double-check all those env() variables are coming in ok.

ohffs left a reply on Calling Mysqldump Via Route Returning An Empty Sql • 2 weeks ago

Maybe check the $returnVar to see if the command is working ok. It might also be because you don't have a terminal STDIN/STDOUT available - not sure. Your system path might also be different when running from the web PHP - you could try adding the full path to mysqldump (often, /usr/bin/mysqldump)

Maybe also look into using the symfony process module (it is bundled as part of Laravel so you shouldn't need to install it). It gives you quite a lot of nice features to run external commands, capture their output/status etc.

31st August, 2018

ohffs left a reply on Finalizing The Project • 3 weeks ago

You're probably better leaving everything un-optimised and explain in the docs how to do it. If it's opensource and someone changes something which you've cached - they're likely to be more confused when the change doesn't show up. If you just say 'if you're running in production run these commands....' You can always just link to the laravel docs on what to do so you don't need to write it yourself.

ohffs left a reply on Finalizing The Project • 3 weeks ago

Maybe documentation & these days if you can provide some kind of docker setup for it (at least as a 'demo mode') that often gets a lot of appreciation too. Really depends on the project though - you haven't really given us much to go on... Do you mean this is an open source app? Or code for a client? Are you asking about automated deployments? CI?

ohffs left a reply on A Question Of Semantics And Concepts • 3 weeks ago

I build apps which generally have a lifespan of 10+ years - the current main one was build over 10 years ago and was never touched or updated and it's a monster :-(

I tend to pick PHP packages for them if it's going to save me a lot of 'fiddly' stuff and time - and if the people who wrote them seem to be fairly committed. So for instance in the 'monster' app there is a whole lot of image storage/processing and I've used the Spatie medialibrary as it does a whole lot of what I'd be implenting myself and does it well. I've also got a markdown converter and a pdf exporter in there as it's a lot of time to do yourself and PHP has some pretty mature packages for it.

For javascript though - it's a harder call. 'Mature' in javascript-land can often seem to mean 'was released more than an hour ago' ;-) I once spent a day implementing a javascript feature and by the time I'd finished the package I was using had gone through two 'major' releases and changed it's API completely :-/

It's always a bit of a judgement call - as your say - time saved vs. abandonded/customisation/etc. If I feel the need to pull in a PHP package I'm not 100% on, I'll quite often wrap it in my own 'decorator' with just the features I need exposed. Then at least if it goes away I can keep my 'business' code the same even if the underlying package has been swapped out.

ohffs left a reply on Handling Major Feed Import Timeout Issues • 3 weeks ago

How big are the inserts? 30 seconds to insert 400 records seems like a long time!

But another solution might be to chunk the data as your doing now - but dispatch each of those chunks as a job? So you'd end up with something like :

foreach($sliced_array_of_elements as $elements) {
    ChunkInsert::dispatch($elements);
}

You could also try wrapping the whole function in a DB::transaction() call - that can speed things up quite a bit too.

30th August, 2018

ohffs left a reply on Php Artisan Not Working In Centos 7 • 3 weeks ago

Allowed memory size of 2097152 bytes is only 2mb of memory. Are you sure you are editing the right config file for your php (php --ini will show you the paths)? Or possibly your hosting company/cpanel is doing something weird... :-/

ohffs left a reply on How Does Laravel Prevent Forged Resource IDs? • 3 weeks ago

I think signed urls is what @snapey was suggesting :-)

29th August, 2018

ohffs left a reply on How Do You Logically Group Tests For A Resource? • 3 weeks ago

If it's checking kind of CRUD stuff where you're just checking users can't mess around I'll quite often end up with something like (in the same test class like PostsTest) :

a_user_can_update_their_own_post();

a_user_cant_update_someone_elses_post();

an_admin_can_update_any_post();

If there's some kind of logical 'feature' going on ontop of the crud I'll split out a separate test - really just because it's easier to find. So at the moment I'm doing code for booking time on bits of equipment and there are a whole lot of things to track - most of which only admins can do. So I have a CRUDdy main BookingTest then separated out EquipmentFaultTest, BookingFailedTest, BookingQueryTest etc.

That being said - I still find myself finding tests buried away in 'the wrong' file and cursing myself ;-)

24th August, 2018

ohffs left a reply on Gitlab • 4 weeks ago

There's an introductory series on using gitlab on leveluptutorials which might help :-)

23rd August, 2018

ohffs left a reply on JSON Column - Find Any Matching Value • 1 month ago

For anyone else who needs to do this, this is what I've got working (assuming your json column is called 'data') :

public static function searchFor(string $term)
{
    return static::whereRaw("JSON_SEARCH(data, 'all', ?) IS NOT NULL", ["%{$term}%"])->get();

}

Then elsewhere you can do :

$results = Model::searchFor('hello');

22nd August, 2018

ohffs left a reply on JSON Column - Find Any Matching Value • 1 month ago

@36864 @bestmomo ah - fair enough I guess. Thanks for the pointer - I can avoid my hacky text column now and feel a little less guilty when I look at the code :-) Thanks again :-)

ohffs left a reply on JSON Column - Find Any Matching Value • 1 month ago

@Dchubb ah - I was hoping the new json syntax in mysql would let me do it natively :-/ Fetching all the records and filtering them would be a bit 'costly' as there are many, many thousands of them :-/

My hacky way around it would be to store the data as one big concatenated text column and do a like query against that - but I'd much rather avoid that if I can...

ohffs left a reply on JSON Column - Find Any Matching Value • 1 month ago

@staudenmeir it's an object - which in turn contains lots of other nested objects. It's pretty much a dump of $request->all() for some complicated forms with 100's of fields.

ohffs started a new conversation JSON Column - Find Any Matching Value • 1 month ago

I have a db with a json column that's used to store a whole lot of nested data. I was wondering if anyone knows if (ideally via Eloquent) you can do something like :

Model::where('mycolumn->*', 'like', '%searchterm%')->get();

I've had a look at the mysql json column docs and nothing was leaping out at me :-/

ohffs started a new conversation Laracon 2018 Videos • 1 month ago

20th August, 2018

ohffs left a reply on Splitting Vue/js Components • 1 month ago

@martinbean it's surprisingly easy if you're happy to embrace the magic webpack is doing :-) Once I realised the async components were a thing - it was only about 15 minutes to change over :-) It is a teeny bit slower to load a page with components as it's fetching them via ajax - so sometimes there's a bit of a jank when it appears - but tbh that's the least of my worries ;-)

I do have the nagging doubt that something, somewhere is going terribly wrong of course - but then that's life as a software dev ;-)

ohffs left a reply on Splitting Vue/js Components • 1 month ago

Just in case anyone else finds this - I've gone down the route of using Vue's [https://vuejs.org/v2/guide/components-dynamic-async.html#Async-Components](Async Components) which combined with the info from the pages above seems to be doing a whole lot of magic I am gladly ignoring for the moment - but it seems to work with a minimum of changes to the code.

A quick how-to:

Install the babel plugin to handle the not-yet-a-standard import() function :

npm install babel-plugin-syntax-dynamic-import --save-dev

Create a .babelrc file in the root of your project :

{
    "presets": [
        "babel-preset-env"
    ],
    "plugins": [
        "babel-plugin-syntax-dynamic-import"
    ]
}

In your app.js file, where you (or at least I was) doing :

Vue.component("order-form", require("./components/OrderForm.vue"));

Replace those require satements with :

Vue.component("order-form", () => import("./components/OrderForm.vue"));

Now when you run npm run dev (or whatever) webpack will magically split your components into different files and load them via ajax when needed in a template. Webpack will give them fairly unhelpful names - so if you care or want more control you can do :

Vue.component("order-form", () => import("./components/OrderForm.vue" /* webpackChunkName: "js/order-form" */));

Which will spit out the needed js into public/js/order-form.js (the default would be something like public/13.js.

Anyway - it's let me 1/2 the size of my app.js bundle - so that's a win for me. Thanks again to @Cronix and @martinbean for the pointers :-)

19th August, 2018

ohffs left a reply on Splitting Vue/js Components • 1 month ago

@Cronix oh! thank you! that's exactly what I was failing to find by myself :-D

18th August, 2018

ohffs left a reply on Splitting Vue/js Components • 1 month ago

@martinbean ah! spiffy! Ta for that :-) I'll have a dig through that tomorrow when I'm not full of beer (a craft beer shop has opened up just round the corner from me - so I'm busy 'supporting local businesses'. :: hic :: ;-) It feels like splitting all this should be quite common - but googling about feels like 'why do you want to do that, you weirdo?' ;-)

Have a good weekend - thanks again :-)

ohffs started a new conversation Splitting Vue/js Components • 1 month ago

I've got an app where the javascript is getting a bit out of hand (~3mb so far and there's a lot more of the app to go). Most of the JS is actually for the admin back-end so it seems a shame to be hitting regular users with a huge bundle when they'll never need to use it.

Anyway - after a bit of googling around I've found roughly 8,000 ways of doing this - none of which seemed terribly helpful ;-) What I'm after is more-or-less a main app.js file with vue + some components/mixins which are used almost everywhere, then on individual pages be able to add in the bigger components that page uses. So in blade terms, something like :

.... regular blade stuff

@push('scripts')

@include('/js/app.js')
@include('/js/componentX.js')
@include('/js/componentY.js');

@endpush

But I'm not sure how to do that or if it's really possible with vue/components :-( Another thought I had was to make something like a 'page bundle' that had all the js needed for that particular page - but that seems like a maintenance nightmare.

Anyone have any pointers? It'd be much appreciated :-)

17th August, 2018

ohffs left a reply on L 5.6 : Unable To Deploy • 1 month ago

I guess it's serving up the contents of the index.php file, rather than running it? You need to make sure you have mod_php installed or php-fpm - have a read through something like this guide to see if you have php set up ok (note it's for php 7.0 - so you might need to adjust it if you need 7.1/7.2).

16th August, 2018

ohffs left a reply on When Laravel 5.7 Release? • 1 month ago

The docs still default to 5.6 - I don't think 5.7 will be officially released until around Laracon EU at the end of the month.

14th August, 2018

ohffs left a reply on 401 On Any New Api Routes • 1 month ago

Glad it helped! :-)

ohffs left a reply on 401 On Any New Api Routes • 1 month ago

Have you done a composer update recently by any chance? A few people seem to have been bitten by the change to cookie's that happened a few days ago : https://laravel.com/docs/5.6/upgrade#upgrade-5.6.30

11th August, 2018

ohffs left a reply on Dusk Configuration; I’m Doing Something Wrong • 1 month ago

Might not be the issue - but I usually use a '.env.dusk' file (no '.local' at the end). Also - you can't use the RefreshDatabase trait - you need to use the DatabaseMigrations one. Because your test is now separate from your actual 'app' (as the browser is different process) it'll get very messy.

ohffs left a reply on Generalising A Problem • 1 month ago

Thanks @jlrdw ,

It is already all html forms - from a previous paper system that was getting way out of hand. I'm looking to re-write it to make it a bit more flexible and maintainable. Especially if other departments want to start creating their own forms & logic - I'd rather not be sat here in two years with an even worse code-mess than I've got just now :-) I'd really like to end up with a kind of modular 'bundle' for each department & it's forms so they could, in theory, do their own thing pretty much.

10th August, 2018

ohffs started a new conversation Generalising A Problem • 1 month ago

'Allo all, one of those 'meandering friday afternoon' questions coming up... ;-)

I've got a horrible old bit of code to handle safety form submissions which needs re-written (it was done about 10yrs ago and has become a mess of fixes/work-arounds down the years). It handles three main types of safety forms which have some shared/common fields.

Each of those forms also comes in two types (kind of 'single user' or 'multi-user'). The multi-user forms are created once, then other people can sign up to say 'yeah, I'm doing this too'.

There's a small amount of logic for each form - an email is sent to the safety admin to give final approval, and some forms also need signed off by a line manager. There's currently(!) no different logic between the three main types of form - just the difference between the single/multi user versions.

At the moment that's all dealt with by some nasty if/elseif/else/switch logic in what you could laughingly call the 'controller' (ie, the app is pretty much one huge php file).

To add a little excitement to my life - another department wants to start using the system, but they have different logic for the forms (of course).

So I'm trying to think of a nice way of abstracting things so I don't end up maintaining another mound of spaghetti in a year or two. Yes, a boy can dream ;-)

Has anyone been down a similar path? I'm sure there's a 'design pattern' I'm struggling to find - or possibly something entirely obvious ;-) The database side isn't so bad - it's more the way of splitting the code up in a way that makes sense and is nice to use, easy to extend etc. Again, a boy can dream ;-)

The first thing that popped into mind was something like :

Forms\
  Department1\
    \Laser
      Controller.php
      Model.php
      Views/
        create/edit/show/...
   \Chemical
     Controller.php....
   \LaserMultiuser
     ...
  Department2\
   \Chemical
    ...

Then at least I could do some kind of mapping between 'create form type A for department1' and the code/layout.

But I'm not at all sure... Self doubt ftw! ;-)

6th August, 2018

ohffs left a reply on Assumptions In The Code • 1 month ago

I think the validation is often dependent on the application. If it's 'add a comment to this booking' you probably don't care beyond the basics, but if it's 'set the angle of ascent of a rocket' you really, really should ;-)

There are also cases where you want to validate everything 'up front' and bail out if anything looks bad before you take any action, and sometimes where you want to just reject invalid stuff but process valid. Sometimes it could be either then you're back to just making it up as you go ;-)

It's a tricky thing to generalise about I think :-)

ohffs left a reply on Assumptions In The Code • 1 month ago

On the 'exceptions or not' side of things, the Python community is quite strong on "Ask forgiveness, not permission". Which kind of comes down to :

try {
  do_a_thing();
} catch ....

rather than :

if (can_do_a_thing()) {
  do_a_thing();
} else ...

I don't think there's much of a consensus in the PHP world though (like most things in PHP really ;-)

In general, possibly because I'm lazy, I let code shoot itself in the foot if there isn't a straightforward way to stop it. Eg, if I have a function which can only accept a User model I'd be happy to :

public function giveCake(User $user)
{
...

But if it's something like it accepts a data structure that should be in a specific format (or sorted or whatever) I'll also allow :

public function kaBoom($data)
{
  // try and process it - either return garbage or blow up

I will try and always blow up if it's a possibly 'dangerous' operation - like 'will this make every user on the site be credited with US$1million if it goes wrong' ;-)

I also try to give variables helpful names if they're not an obvious class/type. So maybe :

public function someBigOperation(array $sortedRatings)
{

At least then if people are too lazy to read the docs then their text-editor/IDE might give them a clue.

But of course I quite often don't follow my own thinking and then curse myself later ;-)

3rd August, 2018

ohffs left a reply on Is Using Id Bad Or Not • 1 month ago

I don't think chosing a unique id of md5($thing) versus a unique id of integer is very different. Either way if someone bad got into your database they could trace who posted what. I really wouldn't worry about it unless you're running some kind of extreme & anonymous website where if it were hacked it could be very bad for users who'd posted crazy stuff (:: cough :: reddit :: cough ::)

Having the ID's exposed in a url is sometimes more of a concern - but in the backend DB I don't see it being a common concern. I might be wrong though :-)

1st August, 2018

ohffs left a reply on Free Domain Name That Let You Change DNS Records? • 1 month ago

You could set up your own DNS server? dnsmasq is pretty easy to set up.

28th July, 2018

ohffs left a reply on MacBook Pro Alternatives • 1 month ago

I've got a 13" MBP and it's ok for coding on (though the new keyboard layout annoys me). If you're the kind of person who likes to be able to see 100 lines of code at a time then it might be a push, but I find it ok. One of my co-workers has a 13" too and likes to use tiny fonts and doesn't seem to have a problem - but he's quite young and hasn't spent 20yrs ruining his eyesight. Yet ;-)

You could always pick up an external monitor sometime later if you feel you need it?

27th July, 2018

ohffs started a new conversation CSS Transitions • 1 month ago

Hi Jeffrey,

Just wondering if there was any mileage in a (possibly quite short) series on CSS transitions? I've been struggling a bit finding good resources for fairly simple things and the docs I can find either seem to fall into the basic vuejs opacity: 0 / opacity: 1 - or leap to a full css animation/keyframe/technicolor/3d thing.

I noticed in one of the videos where you were showing the upcoming new design you had some nice subtle transitions which I've struggled to figure out myself, so I guess you've maybe had a chance to figure them out for your own needs.

Anyway - I'm personally just after the basic 'how to grow a box', 'how to ease in a drop-down' - the stuff old-timers like me used to pull in jquery plugins for and make my poor downtrodden users think 'oh wow! that's amazing!' ;-) As it is I keep seeing really small details in video tutorials which are never explained and thinking (enviously!) 'how do they do that?!' ;-)

ohffs left a reply on DigitalOcean Buckets Are Slow • 1 month ago

I tried a little experiment with Digital Ocean Spaces a while back (like a year or something) and it was weirdly slow back then. It could just be the answer is 'it's slow' :-/

Have you tried doing a speed test via the CLI/API they offer? You could try from a digital ocean server, then try from your own local machine and see if there's a big speed difference.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.