Skip to content

u/Kilenaitor

In this archive from Sep 2012 to Jul 2021

5
posts
25
comments
3
media
88
score

Top posts

Please help. iMac 2011, Custom 3TB hard drive, Ubuntu 12.04. Fan speed immediately revs up to 5000 RPM and climbing. Cannot modify applesmc.768 files, because they immediately change back.

This driving me insane. sensors Output shows applesmc ODD - 1300 HDD - 5346 CPU - 1325 I've tried running as root echo "1" > /sys/devices/platform/applesmc.768/fan2_manual And echo "1200" > /sys/devices/platform/applesmc.768/fan2_output But they immediately change back to their defaults. 0 - fan2_ma...

7 points13 comments
Open on Reddit

Top comments

I get the intent here but I think this is a bit of a disingenuous argument. And I say that as a fan of PHP and someone who thinks it's more than fine for startups.

The "real" answer here is that 99.9% of places aren't going to hit scalability concerns due to PHP. In the event OP's startup does take off, there are plenty of language-agnostic solutions to scalability problems that should be tried first: caches, sharding, more boxes, etc.

Facebook (and Slack) actually did hit the scalability concerns with PHP which is why they're both using Hacklang + HHVM. Point is though that they are absolutely the exception to the rule.

3 points

Are you asking how you would build something like this? Post is lacking details.

What is your current system/setup? What scale do you need? Distributed or colocated?

Simple and small scale, you can set this up with cron and a simple database to store the script+arguments and timestamp. Each new job adds an entry to the DB and cron wakes up a runner script to check the DB every minute and run the stuff scheduled for that moment.

Need something more robust or scalable? Architecture is gonna get more complicated from there.

3 points

I'll take a shot at it. I have no idea what the rest of the code looks like so going to probably just make some assumptions here. Tried to keep the style in spirit even though it's not normally how I'd write code. Feel free to roast me if I'm missing something; I normally write Hack lol.

changepassword.php

require_once('header.php');
use Admin\Auth;

if (isset($_POST['newPassword']) && isset($_POST['oldPassword'])) 
{
    $newPasswordHash = password_hash($_POST['newPassword']);
    $response = Auth::updatePasswordData($_POST['oldPassword'], $newPasswordHash);
    // cut for brevity

Admin/Auth.php

namespace Admin;

abstract class Auth 
{
    public static function updatePasswordData($oldPassword, $newPasswordHash) 
    {
        $userID = $_SESSION['userID'];
        $oldPasswordHash = self::getUserPassword($userID);
        if(password_verify($oldPassword, $oldPasswordHash))
        {
            $result = self::updateUserPassword($userID, $newPasswordHash);
            if($result)
            {
                return 2;
            } 
            else
            {
                return 1;
            } 
        }
        else
        {
            return 0;
        }
    }

    private static function getUserPassword($userID)
    {
        $mysqli = new mysqli('<host>', '<username>', '<password>', '<database>'); // Or a DB singleton 
        if ($mysqli->connect_errno) {
            error_log(sprintf('Failed to connect to MySQL: (%d) %s', $mysqli->connect_errno, $mysqli->connect_error));
            return null;
        }

        $stmt = $mysqli->prepare('SELECT password FROM admins WHERE user_id=?');
        $stmt->bind_param('i', $userID);
        $stmt->execute();
        $result = $stmt->get_result();
        if ($result === null) {
            return null;
        } 

        $row = $result->fetch_assoc();
        $result->free();
        $mysqli->close();

        return $row['password'];
    }

    private static function updateUserPassword($userID, $hashedPassword) 
    {
        $mysqli = new mysqli('<host>', '<username>', '<password>', '<database>'); // Or a DB singleton 
        if ($mysqli->connect_errno) {
            error_log(sprintf('Failed to connect to MySQL: (%d) %s', $mysqli->connect_errno, $mysqli->connect_error));
            return false;
        }

        $stmt = $mysqli->prepare('UPDATE admins SET password=? WHERE user_id=?');
        $stmt->bind_param('si', $hashedPassword, $userID);
        $stmt->execute();
        
        $affectedRows = $mysqli->affected_rows;
        if ($affectedRows === 0) {
            error_log(sprintf('Could not update password for user %d', $userID));
            return false;
        } 

        return true;
    }
}

Edit: For fun. If you've never seen Hack before and are curious to see how they'd subtly differ:

public static async function updatePasswordAsync(
  string $old_password,
  string $new_password,
): Awaitable<void> {
  $user_id = $_SESSION['user_id'];
  $old_password_hash = await self::getUserPasswordAsync($user_id);
  if (password_verify($old_password, $old_password_hash)) {
    await self::updateUserPasswordAsync($user_id, $new_password);
  }
}

Edit 2: Fixed where password_hash was called so it wont get leaked in stacktrace. Whoops.

3 points

Fixed a few things that were either bugging you guys, or bugging us.

Any suggestions as for what to do with the Korean Flag in the bottom corner? The 8 bars is the traditional one so we thought since it's traditional culture, we'd throw that in as well.

Some of us feel the bars are distracting, but then we don't know what to do with the Yin-Yang in the corner.

Any suggestions/critiques are welcome. We do hope for this to be the final iteration of the design though. Thanks guys!

[Edit] Just saying that the shirt it will be printed on will be a Raglan Baseball shirt. So FYI.

//Link to old one: //http://i.imgur.com/ktCu1Gk.jpg

Thanks for all the help!

3 points

Subreddits

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.