Gnome extension keybinding latency

I am building out a gnome extension that will allow me to have several keybinding shortcuts. The first one I am trying to tackle is HJKL for arrow keys like in vim.
I am using the following code to accomplish this:

let mode = Shell.ActionMode.ALL;
let flag = Meta.KeyBindingFlags.NONE;
let settings = getSettings();    

Main.wm.addKeybinding("left-h", settings, flag, mode, () => log('test') );

here is the shortcut schema:

<key type="as" name="left-h">
    <default><![CDATA[['h']]]></default>
    <summary>The shortcut key</summary>
    <description>You can create GTK entry in pref and set it as CDATA</description>
</key>

This all works as expected. My only issue is that there is about one second of latency when the key is pressed to when there is a log to the output. My first thought was that the log is just slow, so I set it up to call a python script with spawn_command_line_sync that is responsible for simulating a key press which also had ~1s of latency after the button was pressed to when the command fired. (I am using a python script for this because I couldn’t find a way to press keys via GJS) Is it possible to get rid of that latency? Right now they keybindings are unusable because of it.

Google maps, call function ONLY after dragging map (not zooming)

So this is working for dragging around on the map but it’s a little too sensitive (if I scroll zoom on the map it calls the function too, and also if I trigger a map marker, which changes the center of the map, it gets called)

So with this working bit of code, how can I refine this to truly only call my searchByState function after dragging around on the map and not when zooming or triggering a marker?

google.maps.event.addListener(map,'idle',function(){
          if(!this.get('dragging') && this.get('oldCenter') && this.get('oldCenter')!==this.getCenter()) {
            var lat = map.getCenter().lat();
            var lon = map.getCenter().lng()

            searchByState(lon,lat);
          }
          if(!this.get('dragging')){
           this.set('oldCenter',this.getCenter())
          }

        });

        google.maps.event.addListener(map,'dragstart',function(){
          this.set('dragging',true);          
        });

        google.maps.event.addListener(map,'dragend',function(){
          this.set('dragging',false);
          google.maps.event.trigger(this,'idle',{});
        });

datatable column filtering with serverside(ajax) doesn’t work

I’m developing with django and javascript with datatable.

I want to apply column filtering in my datatable
(https://datatables.net/extensions/fixedheader/examples/options/columnFiltering.html)

but it works fine without serverside option & ajax (in client side),

but it doesn’t work with serverside option & ajax.

How can i FIX IT? Please help me..T_T

this is my code.

    <table id="sample_table" class="table table-bordered table-hover">
      <thead>
      <tr>
        <th class="sample_id">ID</th>
        <th>date</th>
        <th>serial</th>
        <th>name</th>
        <th>birth</th>
      </tr>
      </thead>
      <tbody id="sample_table_body">
      </tbody>
      <tfoot>
          <tr>
              <th>ID</th>
              <th>date</th>
              <th>serial</th>
              <th>name</th>
              <th>birth</th>
          </tr>
      </tfoot>
    </table>
  </div>
  <!-- /.card-body -->
</div>
var column_list = [
  { "data" : "id" , "className": "sample_id"},
  { "data" : "receiving_at" },
  { "data" : "serialnumber" },
  { "data" : "name" },
  { "data" : "birthday" },
];

$('#sample_table tfoot th').each(function(){
    var title = $("#sample_table thead th").eq( $(this).index() ).text();
    $(this).html('<input type="text" placeholder="Search '+title+'" />' );
});

var sample_table = $('#sample_table').DataTable({
  "paging": true,
  "autoWidth": false,
  "lengthChange": false,
  "ordering": true,
  "processing" : true,  
  "columns": column_list,  
  "order": [ [0, 'desc'] ], 
  "fixedHeader": true,
  "orderCellsTop": true,
  "ajax": {
        url: '/view_datatable/',
        type: 'POST'
  },
  "serverSide" : true, //get data from server
  "initComplete": function() { // column filtering RUN after table loaded .
     $( '#sample_table tfoot input' ).on( 'keyup change clear', function () {
     if ( sample_table.search() !== this.value && this.value.length>0) {
         search_result = sample_table.search( this.value );
         search_result.draw();
     }
   } );
}
});


#view.py
def list_datatable(request, companyname):
    context = {}
    
    if(request.method == "POST"):
        start_page = int(request.POST['start'])
    
        order_direction = request.POST["order[0][dir]"] # direction of ordering(asc, desc)
        order_col_no = request.POST["order[0][column]"] # number of index to sort
        order_col_name = request.POST['columns[' + str(order_col_no) + '][data]'].strip() # name of colum of ordering 


        sample_list_all = Sample.objects.all().order_by(order_col_name)

        sample_list_per_page = []
        for idx, obj in enumerate(sample_list_all[start_page:start_page + 10]):
            data = {}
            data['id'] = obj.id
            data['receiving_at'] = str(obj.receiving_at)
            data['birthday'] = obj.birthday
            data['serialnumber'] = obj.serialnumber
            data['name'] = obj.name
            sample_list_per_page.append(data)

        #-- end of --#

        datalist_to_json = json.dumps(
            {"data": sample_list_per_page, "recordsFiltered": len(sample_list_all), "recordsTotal": len(sample_list_all)}
        ) 
        return HttpResponse(datalist_to_json, content_type="application/json")

THREE.js MIME Javascript module

I am getting this error when trying to load my three.js page live.
In my html I have specified module as my type:

<script type="module" src="./sketch.js"></script>

ERROR:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/html”. Strict MIME type checking is enforced for module scripts per HTML spec.

This is my folder structure. I have the three.js package folder called “three.js-master”
enter image description here

Thank you for your help.

Javascript fire PHP after success

I hope I can get some help over here because i’m stuck with that. I’m kinda new to programing and try to understand how this works.

I’ve this following code to generate my table

<tbody>
    <?php
      $stmt = $pdo->prepare("SELECT * FROM videos");
      $stmt->execute();
      $results = $stmt->fetchAll(PDO::FETCH_OBJ);
      if($stmt->rowCount() > 0){
        foreach($results as $result){?>
        <tr>
          <td class="fw-semibold fs-sm"><?= $result->title; ?></td>
          <?php
            if($result->access == '***'){?>
              <td class="d-none d-sm-table-cell fs-sm">
                <span class="fs-xs fw-semibold d-inline-block py-1 px-3 rounded-pill bg-warning-light text-warning">***</span>
              </td>
          <?php }else{?>
              <td class="d-none d-sm-table-cell fs-sm">
                <span class="fs-xs fw-semibold d-inline-block py-1 px-3 rounded-pill bg-success-light text-success">***</span>
              </td>
          <?php } ?>
          <td class="d-none d-sm-table-cell">
          <?= convert($result->size); ?>
          </td>
          <td>
            <span class="text-muted fs-sm"><?= date( 'd.m.Y H:i', strtotime(str_replace('.','-',$result->date))); ?></span>
          </td>
          <td class="text-center">
            <div class="btn-group">
              <button type="button" class="btn btn-sm btn-alt-secondary" data-bs-toggle="tooltip" title="Edit">
                <i class="fa fa-fw fa-pencil-alt"></i>
              </button>
              <button type="button" class="btn btn-sm btn-alt-secondary" data-bs-toggle="tooltip" title="Share">
                <i class="fa fa-fw fa-share"></i>
              </button>
              <button type="button" class="btn btn-sm btn-alt-secondary" data-bs-toggle="tooltip" title="View">
                <i class="fa fa-fw fa-eye"></i>
              </button>


              <!-- 
                Here is the button to delete with confirmation 'js-swal-confirm' 
                to get the ID from the table i'd use this 
                <?php // $result->id; ?>
              -->
              <button type="button" class="js-swal-confirm btn btn-sm btn-alt-danger" data-bs-toggle="tooltip" title="Delete">
                <i class="fa fa-fw fa-times"></i>
              </button>
            </div>
          </td>
        </tr>
    <?php }
      }
    ?>
</tbody>

now my javascript code where i’m stuck at because I don’t know where I could start with.
I got this code from the internet and changed some codes about it to get it done how I want it.
This is how it looks right now

<script>
  One.onLoad(class {
    static sweetAlert2() {
      let e = Swal.mixin({
        buttonsStyling: !1,
        target: "#page-container",
        customClass: {
          confirmButton: "btn btn-success m-1",
          cancelButton: "btn btn-danger m-1",
          input: "form-control"
        }
      });
      document.querySelector(".js-swal-confirm").addEventListener("click", (t => {
        e.fire({
          title: "Are you sure?",
          text: "You will not be able to recover this file!",
          icon: "warning",
          showCancelButton: !0,
          customClass: {
            confirmButton: "btn btn-danger m-1",
            cancelButton: "btn btn-secondary m-1"
          },
          confirmButtonText: "Yes, delete it!",
          html: !1,
          preConfirm: e => new Promise((e => {
            setTimeout((() => {
              e()
            }), 50)
          }))
        }).then((t => {
          t.value ? e.fire("Deleted!", "Your file has been deleted.", "success") : "cancel" === t.dismiss && e.fire("Cancelled", "Your file is safe :)", "error")
        }))
      }))
    }
    static init() {
      this.sweetAlert2()
    }
  }.init());
</script>

So what I want is, when the button is pressed and clicked on “Yes, delete it!”, it should fire a php script in the background where the ID is posted with a $_GET[''] function so it can delete the entry from the database and even the file from the server. Or is there even a faster better solution for this?
All I want is a security before the file is getting deleted from the table ( mysql, server ) and this popup should warn the user before the file is actuall getting deleted means confirmation with a warning text.
I couldn’t try anything at all because I do not know where to start at all. PHP is no problem, but the javascript part is for me hard. So any help would be amazing.

For a wordle clone on code.org, how can I make it so that words that are in the right spot/in the word turn yellow?

So I am making a wordle clone in code.org using the dataset, yet I am facing two issues.

The first issue is that when I console.log the correct answer, sometimes it says “null” and other times it works without issue.

The second problem is I don’t know how to make the words yellow if they are out of order or in the word. My code is down below.

//Getting Wordle Answer 
var answers = getColumn("Wordle", "validWordleAnswer");
var index = (randomNumber(0, answers.length));
console.log(answers[index]);
var letters =  ["letter1", "letter2", "letter3", "letter4", "letter5"];


    //Checking Words
    onEvent("wordbutton", "click", function( ) {
      var guess = getProperty("wordInput", "text");
      for (var i = 0; i < 5; i++) {
       
    
         if (guess == answers[index]) {
              setProperty(letters[i], "background-color", "green");
            } else if ((answers[index].includes(guess))) {
              setProperty(letters[i], "background-color", "yellow");
            } else {
              setProperty(letters[i], "background-color", "red");
            }
        setProperty(letters[i], "text", guess[i]);
      }
    });

Specifically the else if statement, and the first four lines of code that are my variables

How can I pass a prop to the Link in react because my code is not working

I am trying to make the Link in ServicesLeft component take a prop but it does not work when i use a prop . Below are the necessary codes .

App.js

function App() {
  return (
    <>
      <Router>
        <Routes>
            <Route path="/" exact element={<HomePage/>} />
            <Route path="/whowehelp" exact element={<WhoWeHelp/>} />
            <Route path="/about" exact element={<AboutPage />} />
            <Route path= "/services" exact element= {<ServiceGeneralPage />} />
            <Route path="/caseStudy" exact element={<CaseStudyPage />} />
            <Route path="/contact" exact element={<ContactUs />} />
            <Route path="/seo" exact element={<SEO />} />
        </Routes>
      </Router>
      </>
  );
}

Here is where i am passing the prop

<div className={styles.column1}>
                        <ServicesLeft 
                        title= "Facebook Ads"
                        desc= "Facebook provides an easy-to-use, intuitive campaign interface. We are able to quickly create new campaigns, manage your budget, track analytics, and continuously improve your ROI. Facebook provides one of the best advertising platforms to use and is effective for every business size and industry type."
                        buttonText= "Learn More"
                        mLink = "'/seo'"
                        />
                    </div>


                    <ServicesLeft 
                    title= "Facebook Ads"
                    buttonText= "Learn More"
                    mLink = "'/seo'"
                    />
                

Finally here is where I apply the prop in ServicesLeft

 <div className={styles.leftSideButton}>
                    <Link to= {props.mLink}>
                        <LargePrimaryButton>
                            {props.buttonText}
                        </LargePrimaryButton>
                    </Link>
                
            </div>

                                                          

I have tried setting prop to mLink= ‘/seo’ but that didnt work but if i just insert “/seo” directly , it does work.

Both ng-model and ng-change on input alter the $scope state – which one takes priority

I have the following array of objects

$scope.client.systemAssessments = [
    {
        id: 0,
        name: 'Name 1',
        paused: false
    },
    {
        id: 1,
        name: 'Name 2',
        paused: false
    },
]

I then render some HTML for each assessment:

<div ng-repeat="systemAssessment in client.systemAssessments">
    <span class="switch">
        <input ng-model="systemAssessment.paused" name="{{systemAssessment.name}}" ng-change="onPauseResumeAssessmentHandler(systemAssessment)" type="checkbox" toggle-btn on-type="success">
    </span>
</div>

And my ng-change function looks like this:

  $scope.onPauseResumeAssessmentHandler = function onPauseResumeAssessmentHandler(systemAssessment) {
    //const { id, paused } = systemAssessment;
    //const clientId = $scope.client.clientId;
    console.log(systemAssignedAssessment);

    try {
      throw new Error('ERROR');
      //AssessmentsService.pauseResumeAssessment(clientId ,id, !paused);
    } catch (error) {
      $scope.client.systemAssessments[0].paused = false;
      console.log($scope.client.systemAssessments);
    }
  };

Now since my input checkbox is binded to pausedAssessment.paused, if I check it, the paused property becomes true and the checkbox gets checked, however, I only want it to become checked if AssessmentsService.pauseResumeAssessment(clientId ,id, !paused); does not fail as it’s a POST request.

For example, if the checkbox was unchecked and I clicked it, I’d want it to check only if the POST request goes through and for it to either stay unchecked, or to uncheck itself if the POST request fails.

As you can see in my code snippet, I tried using a try-catch block and then unchecking the first checkbox if the POST request throws an error, however, when I log the $scope.client.systemAssessments in the catch, it shows that the first assessment’s paused property is still set to true, even though you can see that I set it to false.

I assume this happens because of a weird interaction between ng-model and ng-change ( maybe ng-model overwrites the changes I do in ng-change )

How compare arraylist string’s value similary on MongoDB?

I want to find a mean to compare each “adref” value for each iteration if is already present on DB or not, but unfortunately I don’t have enough capacity to be able to approve my code because js doesn’t has my basic programming language, so could someone help me understand better ?

const jList = [];

let info = {
     title: elem.title,
     description: elem.description,
     adref: elem.adref
     }
     
jList.push(info)


for (let info of jList) {
    if ((jList.element.adref) === db.MyCollection.find(jList.element.adref.valueOf()))
        print("item is already existed")
         continue;
          }
    else:
        print("item is not existed")
        db.MyCollection.insertMany( { title: elem.title, description: elem.title, adref: elem.adref,} )
        continue;
      }

Dynamically cross NavBar on multiple pages with JS

Struggling using javascript to span my navbar across multiple pages of my website. The script is not functioning as intended.

Refer to my code here < https://drive.google.com/drive/folders/1BtKtzP703nigRS69aaGhL57riMQUL3Ix?usp=sharing > and let me know if you can spot the error or errors. The script does not work. When commented out, the navbar should disappear but it remains, thus indicating the code isn’t proper. Hoping to find a solution. Thank you.

Sharp disappearing for transient div

I have created a box to toggle between appearing and disappearing via a toggle button.

The problems are:

  • The first time, the appearing height is sharp and not smooth.
  • The disappearing height is happening sharp and at the end instead of smooth.

I am not a web expert. All I have written are what I have got from different places and assembled. Please feel free to fix any other CSS/JS mistakes too. But the above issues are what I am mainly looking for.

function toggle_elem()
{
    var elem = document.getElementById('elemid');
    if(elem.style.display == 'none')
    {
        elem.style.display = 'block';
        window.setTimeout(function(){
            elem.style.opacity = 1;
            elem.style.transform = 'scale(1)';
            elem.style.height = '100px';
        },0);
    }
    else
    {
        elem.style.transform = 'scale(0)';
        window.setTimeout(function(){
            elem.style.display = 'none';
            elem.style.height = '0';
        }, 300);
    }
}
#elemid {
    border: 1px solid black;
    opacity: 0;
    transform: scale(0);
    transition: height 0.3s, width 0.3s, padding 0.3s, visibility 0.3s, 0.3s ease opacity, opacity 0.3s ease-out, 0.3s ease transform;
}
<div>
<button onclick="toggle_elem()">Toggle</button>
</div>

<div id="elemid" style="display:none">aaaaa</div>

<div>
<button >Next button</button>
</div>

how to get value from array inside of array [closed]

I need help on how to get values from an array in an array. Example:

var myArray = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]];
var result = /* I need the second item in the first array of myArray*/

I’m thinking something like this: var result = myArray[0[1]];

Or this: var result = myArray[0].[1];

Is this possible?