entities – Fatal error: Uncaught Error: Call to undefined function file_save_data()

I have few PDF files that I want to save in Drupal with file_save_data function but when I run drush cr I get this error:
Fatal error: Uncaught Error: Call to undefined function file_save_data()

Here is my code:

<?php
  use DrupalnodeEntityNode;
  use DrupalfileEntityFile;
  use DrupalCoreStreamWrapperPublicStream;

  $uploadedFilesPath = PublicStream::basePath() . '/import/program';
  $dataFiles = array();
  $files = array();

  if ($handle = opendir($uploadedFilesPath)) {
    $i = 0;
    while (false !== ($entry = readdir($handle))) {
      if ($entry != "." && $entry != "..") {
        $dataFiles($i) = file_get_contents($uploadedFilesPath . '/' . $entry);
        $files($i) = file_save_data($dataFiles($i), PublicStream::basePath() . '/download/files');
        $i++;
      }
    }
    closedir($handle);
  }
  $random = 'sda';

Any ideas how to fix that?

python – Cannot assign to function call when looping through and converting excel files

With this code:


xls = pd.ExcelFile('test.xlsx')
sn = xls.sheet_names
for i,snlist in list(zip(range(1,13),sn)):
    'df{}'.format(str(i)) =  pd.read_excel('test.xlsx',sheet_name=snlist, skiprows=range(6))

I get this error:

‘df{}’.format(str(i)) = pd.read_excel(‘test.xlsx’,sheet_name=snlist,
skiprows=range(6))
^ SyntaxError: cannot assign to function call

df+str(i) also return error

i want to make result as:
df1 = pd.read_excel.. list1…
df2 = pd.read_excel… list2….

python – What is best practice for getting a variable passed into a function several layers deep in a local function call?

I have a situation as follows, I have a relative path that I want to get for a directory. The directory structure is as follows,

Windows Folder Structure

C:FileFolderLowerLevelThirdLevelscript.py

C:FileFolderFolderOfInterestfilesStuff.txt

Linux Structure

PathAbove/LowerLevel/ThirdLevel/script.py

PathAbove/FileFolder/FolderOfInterest/filesStuff.txt


Top Level

args = parse_args(sys.argv(1:))
main(args.filepath, args.repository)

Function Definitions

main(filepath,repopath)
{
//do stuff with filepath, repopath
    do_stuff()
    
}

do_stuff()
   path_to_repo = rel_path()  
   #use path_to_repo 




def rel_path():
    """
    Gets the relative path two directory levels up where FileFolder folder lives
    """
    return os.path.abspath(os.path.join(os.path.dirname( __file__), '../../', 'FileFolder/FolderOfInterest'))

I have been asked to make this more general so I don’t have to rely on the FileFolder name being ‘FileFolder’ in case somebody has it named differently.

I pass in the path directly to repopath at the start, so I could use that since it’s validated before use. My usual solution is this

My Usual Solution

Pass repository_path from the top level.

main(args.filepath,args.repository)
    repository_path = args.repository

    do_stuff(repository_path)
        rel_path(repository_path)
    def rel_path(repository_path):
        """
        Gets the relative path two directory levels up where galaxy folder lives
        """
        return os.path.abspath(os.path.join(os.path.dirname( repository_path ), '/FileOfInterest'))

It comes up often that I need to pass in information from a higher level function to a lower level function, usually after I realize that info is needed and I want to refactor something to use it for whatever reason. This requires adding an extra argument to multiple functions and changing functionality slightly. There is actually a third function in-between this in my real code, but this illustrates the issue.

Here is my question

My question is this, is there a best practice for passing in information to a lower level function used only inside another function that isn’t called by the main function? Or am I way off base here? Is there any easier way to get the relative path of FolderOfInterest that I’m interested in getting? Typically I have historically programmed in procedural languages and this has come up plenty of times before in the past. But, it also comes up in OOP programming I’ve done before.

This comes up often enough that I thought it was worth asking here. How do I pass information around without requiring rework of multiple parts of my code when that information is embedded at a higher level than where it needs to be used? I’m trying to make this as agnostic as possible with relative paths, function arguments so it’s easier for others to use/modify later, and so people using it don’t have to make changes depending on whether they run it on Linux or Windows.

I hope I’ve written this somewhat clear and this is a useful enough question to be here. I originally had this on stackoverflow, but since it’s more about best practices in software engineering, I put it here.

I’ve marked this as python because that’s what I’m writing in, but this comes up just as much in c, matlab, c++, and other languages I’ve written in that I’m not necessarily tied to the answer being specific to python syntax

c# – Why the update function only call once

I asked about this question How to efficiently implement a 7-segment display? in previous post. Now I just add an update function to the last part of the code to display the time(I don’t bother the exact time at the moment just want to make sure the number change regularly). However,I’m not sure why the update only run once, I checked the answer in this website, mentioned the root cause is gameobject deactivated(Update function only running once) but this is not my case. I tried with void OnMouseDown(){Display(DateTime.Now.Second)}, the number does change according to my mouse button so I’m not sure what wrong with Update function. In addition, I assigned all the variable but it still pop out message unassigned reference exception, not sure where the problem.

using System;
using UnityEngine;

 public class ClockDigit : MonoBehaviour

{

//  Assuming you number your segments as follows:
//   -- 0 --
//  |       |
//  5       1
//  |       |
//   -- 6 --
//  |       |
//  4       2
//  |       |
//   -- 3 --

// Store a lookup table for which segments 
// should be active when displaying each digit.
static readonly bool(,) SEGMENT_IS_ACTIVE = new bool(,) {

    {true,  true,  true,  true,  true,  true,  false}, // 0
    {false, true,  true,  false, false, false, false}, // 1
    {true,  true,  false, true,  true,  false, true }, // 2
    {true,  true,  true,  true,  false, false, true }, // 3
    {false, true,  true,  false, false, true,  true }, // 4
    {true,  false, true,  true,  false, true,  true }, // 5
    {true,  false, true,  true,  true,  true,  true }, // 6
    {true,  true,  true,  false, false, false, false}, // 7
    {true,  true,  true,  true,  true,  true,  true }, // 8
    {true,  true,  true,  true,  false, true,  true }  // 9
};

public Color32 activeColour = Color.red;
public Color32 inactiveColour = Color.black;

public SpriteRenderer() segments = new SpriteRenderer(7);


public void Display(int number)
{
    var digit = number % 10;
    if (digit < 0) digit *= -1;

    for (int i = 0; i < 7; i++)
    {
        if (SEGMENT_IS_ACTIVE(digit, i))
        {
            segments(i).color = activeColour;
        }
        else
        {
            segments(i).color = inactiveColour;
        }
    }
}

  public void Update()
{
    Display(DateTime.Now.Second);
           
}

}

I tried this command also, the infinite loop freeze the Unity and FixedUpdate() command also update the frame only one time.

void Update()
    {while(true)
      Display(DateTime.Now.Second);
    }

enter image description here

c# – How to Call a function from another script?

Well you are doing var cube1 = new Cube1(); which is how you would make an object in C#, but since it is Unity, and this is a MonoBehaviour, you are not supposed to make it like that.

Instead, make a new GameObject and attach the Cube1 script to it.


void Start()
{
    // make a new gameobject.
    GameObject gameObject = new GameObject();

    // attach a Cube1 script to it. note: by doing Cube1 cube = ... as Cube1;
    // cube now holds a reference to the script you added.
    Cube1 cube = gameObject.AddComponent<Cube1>() as Cube1;

    // call the function on that cube.
    cube.Rectangle();
}

Sidenote, if you don’t make an object in the scene that holds the ClockController, it won’t execute the Start() method.


When you already have an existing GameObject (instead of making a new one) that has a script you want to access, you can use gameObject.GetComponent<Cube1>() , store it in a variable (if necessary) and access it that way. You just need to get that specific GameObject to begin with.

8 – How to add an Ajax call to an element that already has callback set?

I want to add an ajax callback to a form element inside a form_alter, but it already has 2 callbacks assigned to it.

When I review:

$form['payment_information']['payment_method']['#ajax']['callback']

it has 2 callbacks already assigned to it.

If I do this:

$form['payment_information']['payment_method']['#ajax'] = [
  'callback' => '_sia_general_get_fee',
  'event' => 'click',
];

My callback is hit on click; but of course, the other 2 callbacks are wiped out and do not work.

If I add something like this:

$form['payment_information']['payment_method']['#ajax']['callback'][] = '_sia_general_get_fee';

then the other callbacks are called; but mine is not – I suspect since I no longer of an event defined.

I am also not sure how the other ajax calls work when they have no events defined for them.

Is there any way to do this?

magento2 – Generate Random numbers for multiple block call

I am trying to implement custom flash toy for website. To do this I have created custom module.

In custom module, I have created a block class. Block class contain the function to generate the Random digits.

Here is my block's Class Name:  WM_Jackson/Block/Index/Index

Random Id generator code in block:

/**
 * generate random number for player
 *
 * @return int
 */

public function playeridGenerator()
{   
     $ran = rand(10, 999999);
    return $ran;
}

This rando Id generator code works fine when I call my block in cms page using below code:

{{block class="WMJacksonBlockIndexIndex" template="WM_Jackson::flash_elem.phtml" }}

But when I add multiple blocks on the same page, it generates the duplicate ids for all the blocks.

for example if I add block code 3 times, It shows flash player 3 times but it shows same id for 3players. Hence when user try to interact with Flash show, only first player works.

  {{block class="WMJacksonBlockIndexIndex" template="WM_Jackson::flash_elem.phtml" }}
  {{block class="WMJacksonBlockIndexIndex" template="WM_Jackson::flash_elem.phtml" }}
  {{block class="WMJacksonBlockIndexIndex" template="WM_Jackson::flash_elem.phtml" }}

Above code renders output 3 times but block function playeridGenerator() is generating same number 3 times.

How can I generate Random numbers when calling blocks multiple times? Is there any native library in magento for this?

Any help would be appreciated.

microsoft word – What do you call Someone who is stuck up and expects everyone else to deal with them. They act like their important and rich but aren’t

I have a cousin who grew up very well off. He is very rude and will randomly snap at people for little things. His father recently cut him off because he has always been bad with money. He refused to hold a job for too long because he feels like he deserves better. He has unrealistically high expectations for life. He thinks he deserves to get a high-paying job where he doesn’t have to work too much right off the back. He has always acted like he was above everyone else because of his dad’s money, but now he broke. The thing is he still behaves the same way even though he doesn’t have any money. I’m trying to find a word that perfectly describes him. So what do you call a rude person who acts like their rich but is actually broke?