|
I'm bored on a Saturday too, let's do some casual golfing:code:
Of course you could inline the array three times to make it just one line, and of course you could chop variable names down, but I think this is as logically compressed as it can get. I would bet there's a way to arrange ow and uw combinations to fall in a pattern in the encoding that you could exclude them mathematically, but I don't think that'd be much simpler in the end (it would certainly be faster than string comparison if you needed it stupid fast though). Fun fact: You can modulo encode any number of dimensions of integer coordinates as long as they have fixed bounds per dimension, up to whatever size of integer you can store. You can then perform operations on the integers themselves rather than needing to store coordinates. This is great for stuff like n-dimensional chessboards. Ranzear fucked around with this message at 22:20 on Jan 27, 2019 |
# ? Jan 27, 2019 22:12 |
|
|
# ? May 19, 2024 15:49 |
|
Ranzear posted:I'm bored on a Saturday too, let's do some casual golfing: Whoa, I hadn't thought of that! And yeah, that results number is correct! I took a glance through your results and nothing looked like it was missing. And yeah, I did realize I could glom the array onto the boolean that's in bit 1 of the ternary. I just wish that I could use the truncated ternary, but when you use it after an echo, it echoes "1" when bit 1 is true, so no bueno. I'm definitely gonna give this a shot too! I came to programming from linguistics instead of math, so mathematical solutions don't immediately jump out at me. Thanks!
|
# ? Jan 27, 2019 23:10 |
|
Kraus posted:I came to programming from linguistics instead of math, so mathematical solutions don't immediately jump out at me. Just beware of tailored solutions like this. Most would have done a fixed shift for each coordinate to encode into one integer (each dimension gets n bits), but mine are arbitrary to make a continuous set that can be iterated over. Also keep in mind that code golf code is never good code. You should keep the arrays separate for clarity of purpose, and then generalize the implementation using the length of each so you don't have to muck about with literals in the code just to alter any of the arrays: code:
Ranzear fucked around with this message at 01:48 on Jan 28, 2019 |
# ? Jan 28, 2019 01:30 |
|
Ranzear posted:Just beware of tailored solutions like this. Most would have done a fixed shift for each coordinate to encode into one integer (each dimension gets n bits), but mine are arbitrary to make a continuous set that can be iterated over. Dude, oh yeah, this is for funsies, so I'm intentionally breaking all kinds of good practices just for shits and giggles. I promise my professional code looks nothing like this. Edit: Yeah, I'm abusing the fact that strpos can't possibly return 0. Kraus fucked around with this message at 01:54 on Jan 28, 2019 |
# ? Jan 28, 2019 01:51 |
|
Right, but a little bit of golfing can help. This reduced three ugly nested loops to just one, reduced literals in the block, split concatenation over more than one line. and avoided unnecessary assignments. I would call the functional parts of that final version good enough for the kind of work I do. Anyway, because I hate string comparison, here's the changes for a true turbo(nerd) version: code:
code:
I've put literals back in the block again but ¯\_(ツ)_/¯ you already had two there for strpos anyway. Ranzear fucked around with this message at 02:14 on Jan 28, 2019 |
# ? Jan 28, 2019 02:09 |
|
Ranzear posted:Right, but a little bit of golfing can help. This reduced three ugly nested loops to just one, reduced literals in the block, split concatenation over more than one line. and avoided unnecessary assignments. I would call the functional parts of that final version good enough for the kind of work I do. Huh, yeah, that makes a hell of a lot of sense. And yeah, those arrays were organized in a way a linguist would do it, from the top left corner of a consonant chart, to the lower right.
|
# ? Jan 28, 2019 02:16 |
|
I'm reading a txt file and the array looks something like this:code:
I know I can loop thru this array, but I wasn't sure how to group the data after finding the string. (i don't need to keep the order of the keys in order) my desired output would be something like: code:
|
# ? Mar 15, 2019 23:54 |
|
Don't know if this helps, been a while since I've been in PHP land, but I googled explode into multi dimensional array and got this SO: https://stackoverflow.com/questions/21463420/php-explode-and-assign-it-to-a-multi-dimensional-array Looks like kind of what you're looking for, if you replace the OPs line number with your Energy entry.
|
# ? Mar 16, 2019 00:33 |
|
A newbie question: when should I stop developing frontends in PHP and switch over to something like Vue or React? I’ve been creating a site using Laravel which has been great for getting all the backend functionality that I want, but for the front end I’ve been using basic views using Bootstrap with a dash of jquery thrown in when I need something a bit more dynamic (datatables, autocomplete lookups etc). As I’m adding more functionality in I’m finding that the jquery libraries I’m using aren’t cutting it for me and I’m coming to the conclusion that it’s time to learn a front end framework. But it seems to me that React etc all expect to be handling all of the front end as a single page app and I can’t just replace my jquery stuff with equivalent React components and call it a day, or at least that wouldn’t be optimal. Nor do Bootstrap components appear to play nicely when used within React components, although another framework like Bulma looks like it might work a bit better. What to do?
|
# ? Mar 16, 2019 10:52 |
|
Mr Crucial posted:But it seems to me that React etc all expect to be handling all of the front end as a single page app and I can't just replace my jquery stuff with equivalent React components and call it a day, or at least that wouldn't be optimal. You've correctly identified the main problem with a lot of framework code - it's often so highly opinionated that it's effectively all or nothing. Vue seems to be the non-opinionated choice when you need reusable components that render client-side. I've had some luck with it, but I don't speak it idiomatically and haven't used many third party libraries for it. If you can talk more about the specific problems you're struggling to solve with jQuery, we might be able to provide more help. It remains as a good tool for simple interactivity, but keep in mind that it can't interact at all with React and Vue components because of how those libraries operate. McGlockenshire fucked around with this message at 19:21 on Mar 16, 2019 |
# ? Mar 16, 2019 19:19 |
|
McGlockenshire posted:If you can talk more about the specific problems you're struggling to solve with jQuery, we might be able to provide more help. It remains as a good tool for simple interactivity, but keep in mind that it can't interact at all with React and Vue components because of how those libraries operate. I'm building what is basically a big CRUD up for managing some old historic data. I've been writing an API as part of this but my views are driven by Eloquent queries in my controllers, the API is mainly for bulk-uploading stuff from Excel or CSV. A couple of specific issues I'm having: I've been using MDBootstrap datatables on some of my index views so I can do some basic searching and sorting, but as the results get bigger it takes longer and longer to actually draw the table. The worst culprit currently has about 1,000 records but it could eventually end up with 10 times that amount. I know what I need to do is retrieve the results from the API and enable some sort of pagination, but I'm unsure of the best way to do this. MDB supports APIs for datatables but the documentation is really poor and I haven't figured out how to get it working yet, nor does it support API level pagination from what I can tell. Another example is using autocomplete on fields to establish relationships, so I can do a text-lookup based on 'name' or some other meaningful attribute but actually build the relationship built on ID in a related hidden field. I have some custom code that does this as well as clearing the relationship if I delete the field. I haven't seen any pre-built components that can do this. I'm sure these aren't difficult things for a veteran web coder but for my part I don't want to start down the wrong path and end up wasting a lot of time learning something like React or Vue if there's a better way.
|
# ? Mar 17, 2019 16:54 |
|
Mr Crucial posted:A newbie question: when should I stop developing frontends in PHP and switch over to something like Vue or React? As mentioned already, Vue is very flexible with how much of the framework you use. You can start with just a few pages at a time and then gradually change into a SPA if you want to. You can also just use components where needed and leave the rest as is.
|
# ? Mar 18, 2019 14:20 |
|
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.
|
# ? Apr 11, 2019 15:41 |
|
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. Master_Odin fucked around with this message at 04:30 on Apr 12, 2019 |
# ? Apr 12, 2019 04:27 |
|
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). 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.
|
# ? Apr 15, 2019 22:08 |
|
kiwid posted: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. Hah! Based on my experience the fact that you're asking these questions already puts you head and shoulders above 95% of the php programmers I've interacted with.
|
# ? Apr 15, 2019 22:23 |
|
What are some common ways to refactor poo poo like this? Imagine functions.php with 500 functions just like thiscode:
|
# ? Nov 12, 2019 15:40 |
|
Create an Employee class with an isActive() method that gets populated from the start when you load it from an EmployeeStorage interface via the GetById(int) method. You'll implement this interface several times over with a SQL version sitting at the bottom, then several decorators on top to handle things like validation and caching. Or at least that's how I build business software.
|
# ? Nov 12, 2019 20:31 |
rt4 posted:Create an Employee class with an isActive() method that gets populated from the start when you load it from an EmployeeStorage interface via the GetById(int) method. You'll implement this interface several times over with a SQL version sitting at the bottom, then several decorators on top to handle things like validation and caching. Object-Relational Mapping (ORM) is probably what OP should Google to find out more Django has a great one for the python world: https://docs.djangoproject.com/en/2.2/topics/db/queries/ Hibernate is an option over in Java land There's probably a bunch of different ones for PHP but I haven't done PHP in forever so not sure what is preferred there these days Maybe Laravel? https://laravel.com/docs/5.0/eloquent
|
|
# ? Nov 14, 2019 03:36 |
|
Eloquent is ActiveRecord, which breaks the Single Responsibility Principle, the single most important thing to understand when doing serious OO stuff. That article is about Rails, but it applies equally to any ActiveRecord implementation. Instead, consider a Data Mapper, like Doctrine.
|
# ? Nov 14, 2019 04:31 |
|
I am building an IIS-based PHP web site on AWS located in three regions across the globe. On the back end I have a trio of database servers replicating across those regions and I want each pool of web servers to access their local database node above all the others. I have a single DFS share that spans the three regions so I can make a single code push to the DFS share and all web servers in each of the three pools gets an update. So I have created a test Config.php file that looks like this: code:
Hello OS: Windows_NT AZ: us-west-2a Server: 10.1.1.50 as expected. But when I run the script by accessing it in IIS I get Hello OS: Windows_NT AZ: Server: Somehow PHP is not able to fetch EC2-InstanceAZ from the list of system variables inside IIS even though it can pull a different system variable. Does anyone have an idea?
|
# ? Dec 8, 2019 22:31 |
At what point is your environment variable getting set? As far as I understand IIS architecture, you run IIS as a system service, which does not inherit any environment, and IIS in turn runs workers such as PHP FastCGI in an application pool, which does not inherit any environment either. So you'd have to configure the environment at the application pool level.
|
|
# ? Dec 9, 2019 15:02 |
|
nielsm posted:At what point is your environment variable getting set? These are AWS EC2 instances, and upon launch they pull AZ information from http://169.254.169.254/latest/meta-data/placement/availability-zone and shoves it into a system variable called EC2-InstanceAZ. I agree about IIS running as a system service, and fast CGI running in a different environment, but System variables should be available to all sessions (as opposed to user variables that are specific to specific sessions). What is bugging me is that I can pull other system variables (like OS, DriverData) but EC2-InstanceAZ, EC2-InstanceId, etc chokes. Agrikk fucked around with this message at 20:33 on Dec 9, 2019 |
# ? Dec 9, 2019 19:43 |
|
Agrikk posted:I am building an IIS-based PHP web site on AWS But why??
|
# ? Dec 10, 2019 06:34 |
|
Agrikk posted:These are AWS EC2 instances, and upon launch they pull AZ information from http://169.254.169.254/latest/meta-data/placement/availability-zone and shoves it into a system variable called EC2-InstanceAZ. I agree about IIS running as a system service, and fast CGI running in a different environment, but System variables should be available to all sessions (as opposed to user variables that are specific to specific sessions). A few things:
itskage posted:But why?? Also this, especially the multi-AZ DFS
|
# ? Dec 10, 2019 14:43 |
|
Pile Of Garbage posted:A few things: The variables do not show up in phpinfo() and they are in the list under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and IIS is being restarted. itskage posted:But why?? quote:Also this, especially the multi-AZ DFS Because I have some spare time, and the free resources with which to goof off . And most importantly, because I can.
|
# ? Dec 11, 2019 08:14 |
|
I recently discovered Psalm and I really like it. I put its generic notation into our custom orm and now it is giving the right autocompletes & type checking. Plus all the issues a static analyzer can find.
|
# ? Dec 11, 2019 15:45 |
|
It turned out to be an IIS thing, not a PHP thing, but the answer was to turn on "Load User Profile" for the application pool.
|
# ? Dec 11, 2019 17:35 |
|
Agrikk posted:The variables do not show up in phpinfo() and they are in the list under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and IIS is being restarted. Right but for your own sanity why not use a Linux box for PHP and have environment variables just available to you without stuffing around?
|
# ? Dec 11, 2019 21:43 |
|
a hot gujju bhabhi posted:Right but for your own sanity why not use a Linux box for PHP and have environment variables just available to you without stuffing around? I've been a windows guy for decades now. While I can fumble my way around a linux box and make it work, I am way more familiar with the idiosyncrasies of WISP than LAMP (present issue aside). I just don't find Linux boxes intuitive.
|
# ? Dec 11, 2019 21:50 |
|
If you're just playing around to learn, you'll get way more bang for your buck out of learning a better setup. Depends on what your goals are I guess. e: I posted a guide to running php+nginx on windows in here a bit ago if that's of any interest. But that's really for local dev. Production should go on linux. itskage fucked around with this message at 06:48 on Dec 13, 2019 |
# ? Dec 13, 2019 06:46 |
|
Eh, I hear what you are saying and ordinarily I recommend going LAMP to learn PHP, but in this case I’m building a Rube Goldberg setup intentionally. As it turns out, the back-end is actually a set of databases in three regions including Aurora Postgres, RDS SQL Server, SQL Server Availability Groups and stand-alone but load balanced SQL on EC2. All serving up the same data sets. So PHP on IIS with the web sites running off of DFS is hardly the weirdest design decision I have going on here.
|
# ? Dec 13, 2019 17:20 |
|
Agrikk posted:I've been a windows guy for decades now. While I can fumble my way around a linux box and make it work, I am way more familiar with the idiosyncrasies of WISP than LAMP (present issue aside). I just don't find Linux boxes intuitive. These days it's basically just a matter of pulling a docker image and starting it up, I'd really encourage you to take a look into it just for the sake of learning some cool new poo poo that will make your life much easier.
|
# ? Dec 20, 2019 00:51 |
|
Looking for memcached help now. Same app as above... So I have a SQL Server table that is [userID],[timestamp],[data1] and I have a PHP-based web application that returns [data1] for all [timestamp] for a specific [userID]. It returns in a tabular format: http://folding.rainwalk.net/UserHourlySummary.php?UserName=Agrikk&TeamNumber=33 I'm experimenting with AWS Elasticache to speed up database performance and I'm wondering how to make it all work. I understand the basic mechanism with PHP that you write a check to see if the key exists in cache then use that, and if it doesn't then fetch it from a database and also copy it into cache. My question is more around how memcached "knows" that data in the database has been updated. If the above table receives INSERTS at a rate of one batch every 60 minutes, and data older than 14 days is purged, what is the optimal way to fetch the data in PHP so that data lives in cache for 14 days and what is the optimal way to retrieve the data during page load so that it pulls the majority of the data from cache and the remainder from the database? Right now my PHP page runs a SELECT statement and then uses a code:
What is the best practice here? Agrikk fucked around with this message at 02:22 on Dec 24, 2019 |
# ? Dec 24, 2019 02:15 |
|
I haven't used PHP for a while and I'm doing a Symfony video tutorial and the guy keeps writing function calls like code:
Please correct me if I am wrong.
|
# ? Feb 18, 2020 19:49 |
|
That's an IDE thing, PHP does not support named parameters unfortunately. PHPStorm refers to it as inlay hints.
|
# ? Feb 18, 2020 23:08 |
|
My work is having me start in on something on the web that is real time, amongst many users. This could be a chat or a game. I'm only starting to become familiar with this kind of development, so I first looked into Ratchet since I know a bit about PHP. I foolishly installed it onto our shared hosting. I learned a lot; including installing and messing with stuff in bash. But it doesn't allow websockets or listening ports. Is Ratchet still in use? Any information on popular services that use it? Should I be using Symfony instead? What should I be using? What should I be using as a VPS just to get started?
|
# ? Apr 10, 2020 19:59 |
|
Use any VPS you like. Check AwfulMart for some decent hosts with goon discounts. PHP is not well suited to long-running processes. Writing the main app in PHP is usually not a terrible idea, but use something else for the websocket. Javascript is a popular choice, although it's a massive footgun. I'd pick Go.
|
# ? Apr 10, 2020 20:40 |
|
Good Sphere posted:What should I be using as a VPS just to get started? If your employer is paying the bill then just go with AWS.
|
# ? Apr 11, 2020 13:42 |
|
|
# ? May 19, 2024 15:49 |
|
Thanks for the suggestions. They got Kamatera Ubuntu server with nginx. I logged into Kamatera's dashboard for the account, and ssh'd in Mac OS's Terminal. I don't know where to even start. I'm so used to using an ftp client and the like, and I don't even know how with this yet, or if I should. A new frontier for me.
|
# ? Apr 14, 2020 18:52 |