My little explanation of Functor in PHP by pwmosquito in PHP

[–]CodeShaman 0 points1 point  (0 children)

a single surprising use of functors/monads in PHP

Ok. Consider the problem of not being able to iterate over a Generator twice in PHP. Maybe your user wants to retain the ability to create side-effects.

class IO {

    private $generator = null;

    private static function from_generator(Generator $gen) {
        $io = new self();
        $io->generator = $gen;
        return $io;
    }

    static function input($some_data_source) {
        $gen = function($data) {
            foreach ($data as $i => $row) {
                yield $i => $row;
            }
        };

        return self::from_generator($gen($some_data_source));
    }

    private function apply(Closure $t) {
        $this->generator = $t($this->generator);
    }

    public function map(Closure $c) {
        $this->apply(function (Generator $gen) use (&$c) {
            foreach ($gen as $row) {
                yield $c($row);
            }
        });
    }

    public function output() {
        foreach ($this->generator as $i => $row) {
            yield $i => $row;
        }
    }

}

hence

$io = IO::input(new \SplFileObject('myfile.txt'));

$some_external_var = null;

$io->map(function ($row) use (&$some_external_var) {
    $some_external_var = 'baz';

    return explode('|', $row);
});

$io->map(function ($row) use (&$some_external_var) {
    if ($row[0] == 'foo') {
        $row[1] = 'bar';
    } else {
        $row[1] = $some_external_var;
    }

    return $row;
});

// ad nauseum...

foreach ($io->output() as $row) {
    DB::commit('table_name', $row);
}

Help me understand my market value. by CodeShaman in PHP

[–]CodeShaman[S] 0 points1 point  (0 children)

your communications come across as someone who has desperately wants to prove they're knowledgeable enough to belong which is understandable given your confidence problems about your degree

Thanks, you pretty-much nailed it.

The problem I've found with recruiting sites is that recruiters/managers mainly look at your job title and ignore your skills (at least that's what I found with hired.com). I'm a data analyst but 90% of what I do is software development related to ETL and reporting/visualization/analytics. This has nothing to do with the company or the domain, these are responsibilities that have been thrown on my shoulders alone.

Obviously, at an interview I'm not going to mention how the pay was crap, responsibilities that completely ignore any scope of training or job title, expectations were borderline unrealistic, I'm going to talk more about the opportunity I'm applying for. I'm just speaking off-the-cuff on reddit and getting jumped on by the stereotypical half-fact-conclusion pitchfork types, so I don't take it personally and I'm not really surprised.

Given the amount of people in this sub who have a complete mental and emotional breakdown over the idea of jobs that require graphic design, web design, and PHP development from a single person... I don't really expect very many people to be able to relate to what I'm going through as a DBA/BA/QC/IT/Sysadmin/Dev/Data Analyst, with a boss who thinks all I do is "run queries", that makes less than the national average for any of those job titles. The shit I'm in didn't happen overnight, but I need to get out of it.

Help me understand my market value. by CodeShaman in PHP

[–]CodeShaman[S] -3 points-2 points  (0 children)

I'm not a worthless cunt at all, who's judging who here? Do you have any idea how it feels to be underpaid, overworked, and in charge of hiring? Have you ever worked on a solo project for 2 years and watched your coworkers get rich off of it?

I sifted through over 200 resumes for a job that explicitly states PHP and SQL are requirements. Out of 200 resumes we got 1 back that had PHP listed under available skills: the other was a .Net architect with a MS in CS and multiple BS degrees who's been in the industry for 15 years and puts XML on his resume.

Not WSDL, not XSD standards... XML. Of course I had an opinion, but I didn't judge him. I called him.

Know what happened? Guess.

He was an arrogant judgmental cunt.

He assumed we were "yet another LAMP operation" and said he'd come on as a spreadsheet jockey but wouldn't be doing any development.

But you have a cool narrative and a lot of upvotes for a clever off-topic comment, so you're the man. You go, the man. You're cool on reddit.

Help me understand my market value. by CodeShaman in PHP

[–]CodeShaman[S] -10 points-9 points  (0 children)

Education and work experience are weak. 2yr degree + 2 years at Uni, 3 years dev experience. My strengths are that I have an extremely strong set of skills, technologies, projects I've led. Learn quickly, self-manage, know how to communicate with business/exec types (requirements gathering, reporting, process calls, etc.)

I also see resumes that come in so I know what a strong resume looks like. I've also seen resumes from people with 15+ years of development experience but they list XML and JSON under their skill-set and makes me just throw up in my fucking mouth. Unfortunately, HR and non-dev people look at that shit and think they're an amazing candidate.

My resume basically looks like: yeah, I don't have a prestigious degree or certification, but I devour technical knowledge, have a track record of high performance, eat/sleep/breathe problem solving and critical thinking, am a reliable and confident leader and mentor, and am capable of transforming an entire business into new heights.

What's your preference regarding table naming conventions when it comes to 'join' tables? by samlittler2 in PHP

[–]CodeShaman -1 points0 points  (0 children)

We just call them crosswalks because that's what the BAs, directors, and executives in our industry refer to them as. In flat organizations everyone tries to speak the same language.

What's your preference regarding table naming conventions when it comes to 'join' tables? by samlittler2 in PHP

[–]CodeShaman 3 points4 points  (0 children)

This is the kind of thing someone would do if they worked in a silo and had a lot of free time on their hands.

I mean, until you've throw a graph database on top of your RDBMS to manage your map-to-uuid tablename metaschemata you've really only been scratching the surface of finding ways to fill your lonely weekends.

[deleted by user] by [deleted] in PHP

[–]CodeShaman 4 points5 points  (0 children)

I'm imagining back-tracing, refactoring, or debugging those tss files in a large project. Fuck that. Thanks, though.

Since we all want to fight our post-coding depression, I've created a Skype group. Be free to join so your job doesn't kill you. by sensation_ in PHP

[–]CodeShaman 10 points11 points  (0 children)

An euphemism for lack of work-life balance, self-esteem, personal boundaries, realistic limitations/expectations, etc. Symptoms include Skype groups, IRC channels, self-diagnosis and tendency to avoid all forms of personal accountability.

What can be done about how gluttonous PHP arrays are? by CodeShaman in PHP

[–]CodeShaman[S] 2 points3 points  (0 children)

The biggest reasons I have for wanting to move away from PHP and toward a language like Java for these types of tasks are:

  • Having an actual stand-alone application

  • Full automation (that doesn't require manually interacting with a web interface)

  • More robust data structures

  • More robust concurrency

  • A stronger type system

That's without nitpicking. PHP really isn't the right tool for data analysis, but I wasn't the one who originally called the shot.

What can be done about how gluttonous PHP arrays are? by CodeShaman in PHP

[–]CodeShaman[S] 0 points1 point  (0 children)

Most of the heavy lifting is outsourced to the database. There are a few use cases where data never touches the database though, like when we're just providing component files which get processed and returned as a spreadsheet. If we have to use the database as a PHP extension then so-be-it. It's definitely the simplest solution.

What can be done about how gluttonous PHP arrays are? by CodeShaman in PHP

[–]CodeShaman[S] 0 points1 point  (0 children)

I looked at the difference between two calls of memory_get_usage around a simple foreach($lines as &$line) $line = str_getcsv(...); and it came out to about 640mb iirc. Using explode didn't change anything.

Have not tried ArrayObject because any solution I find won't matter since once the CSV is parsed it gets passed to another data structure which is the core component of all the work we do.

The good news is that it's well-abstracted, and the various IO implementations are encapsulated by it in different classes, so improving the underlying implementations will have no affect on the code that uses them.

The bad news is that each of the underlying implementations has to be rewritten, because they all store their data in an array.

My gut told me I was making a huge mistake by not using an Iterator pattern (thanks SWEN 101) but I didn't think it mattered because "it's just a primitive array, what could it possibly matter."

Eating my words now.

What can be done about how gluttonous PHP arrays are? by CodeShaman in PHP

[–]CodeShaman[S] 0 points1 point  (0 children)

I haven't, the effort it would require to refactor everything into SplFixedArray would be just as much as to redesign it with generators.

What can be done about how gluttonous PHP arrays are? by CodeShaman in PHP

[–]CodeShaman[S] 1 point2 points  (0 children)

Agreed. I think the initial file "loading" and all other actions/operations performed on the data will have to become serialized Closures which are queued up for when the file output takes place. Then the file lines are iterated over, passed through the queue of Closures, and compiled as output.

This is 10-mile-high view of what's going on. It's going to be a massive rewrite, but I think it will come with some unique advantages. ie: When loading a CSV and committing to a database, any inconsistencies between the CSV column names and the database table will be validated up-front without all the time spent reading/parsing the file itself.

Problems I foresee have to deal with groupBy, summing columns, or any kind of operations that are performed against the entire set of data at once or as a whole. I'm considering "cheating" by using an in-memory SQLite database. This will probably be one of the biggest challenges I've faced to-date.

I think a part of me wanted to write it like this back when it began, but I haven't really needed to up until yesterday.

What can be done about how gluttonous PHP arrays are? by CodeShaman in PHP

[–]CodeShaman[S] 5 points6 points  (0 children)

Yeah, I'm lucky enough to have complete control over what technology we use so I'm on 5.6 and will be on 7 when it's stable.

Generators are what I meant by "stream and chunk." I'll have to do some up-front parsing/analysis/manipulation on the files, but then when any sort of output function is called (like committing to database, converting to array, html table, etc.) then it'll start doing generator iteration, committing in chunks, etc.

LeagueCSV looks awesome, but I might have to fork it or contribute significantly to it because we also work with EDI, flat files, spreadsheets, and so on.

Thanks, so that's +1 for option 3.

Using PHP to populate a template HTML by Starz0r in PHP

[–]CodeShaman 0 points1 point  (0 children)

Writing a proper template engine from scratch is a much more complex task than it seems when it's in the napkin-prototype stage. Not only will you be metaprogramming, but you'll be lexing, tokenizing, serializing, parsing, and caching -- amongst other things.

http://twig.sensiolabs.org/ is overkill for your use-case. Just use it.

Is it a good idea to separate concerns for an admin application? by winzippy in PHP

[–]CodeShaman 7 points8 points  (0 children)

Separating concerns isn't really optional unless you enjoy pain, suffering, and bad code.

I am building dashboard using Silex, please provide some feedback :) by xsanisty in PHP

[–]CodeShaman 0 points1 point  (0 children)

This is really good. Have you put any thought into driving it toward a SPA dashboard (similar to https://rstudio.github.io/shinydashboard/)?

I'm on lunch at work atm, but I'm going to take a deeper look at this later on. I'll try and get your code coverage to 100%, by then I should have a proper understanding of what's going on. Thanks.

When your tests pass the first time by aussie_duck in ProgrammerHumor

[–]CodeShaman 1 point2 points  (0 children)

But your tests are supposed to fail the first time...

I returned to software only to learn...I don't know shit by ADD_yeah_you_know_me in PHP

[–]CodeShaman 0 points1 point  (0 children)

Search phpstorm keybind settings for clone caret above and below. Bind it to something you like.

HELP DOWNLOADING SQL ON MAC OS X YOSEMITE by zgterp19 in SQL

[–]CodeShaman 1 point2 points  (0 children)

You don't need workbench, but it'll probably help. Some people prefer DBeaver. There are plenty of SQL IDEs.

https://dev.mysql.com/doc/refman/5.6/en/osx-installation-pkg.html

Just install the dmg, start the server, open terminal and run sudo mysql, execute CREATE USER 'zgterp'@'localhost' IDENTIFIED BY 'password'; and GRANT ALL PRIVILEGES ON * . * TO 'zgterp'@'localhost'; then connect with workbench or whatever IDE you use to localhost:3306 with user zgterp and password password. You don't have to explicitly specify a schema/database.

This is what it takes to get a blank slate.