Determine if a JavaScript function is a bound function

Both bound functions and arrow functions do not have a prototype property: typeof (function() {}).prototype // ‘object’ as usual typeof (function() {}).bind(null).prototype // ‘undefined’! typeof (() => {}).prototype // ‘undefined’! This is not 100% safe since you could still manually assign this property (although that’d be weird). As such, a simple way to check for … Read more

Passing elements of a List as parameters to a function with variable arguments

Take a look at this example, I will define a function printme that takes vargs of type String def printme(s: String*) = s.foreach(println) scala> printme(List(“a”,”b”,”c”)) <console>:9: error: type mismatch; found : List[String] required: String printme(List(a,b,c)) What you really need to un-pack the list into arguments with the :_* operator scala> val mylist = List(“1″,”2″,”3”) scala> … Read more

Javascript wait() function [closed]

Javascript isn’t threaded, so a “wait” would freeze the entire page (and probably cause the browser to stop running the script entirely). To specifically address your problem, you should remove the brackets after donothing in your setTimeout call, and make waitsecs a number not a string: console.log(‘before’); setTimeout(donothing,500); // run donothing after 0.5 seconds console.log(‘after’); … Read more

Find nth SET bit in an int

Nowadays this is very easy with PDEP from the BMI2 instruction set. Here is a 64-bit version with some examples: #include <cassert> #include <cstdint> #include <x86intrin.h> inline uint64_t nthset(uint64_t x, unsigned n) { return _pdep_u64(1ULL << n, x); } int main() { assert(nthset(0b0000’1101’1000’0100’1100’1000’1010’0000, 0) == 0b0000’0000’0000’0000’0000’0000’0010’0000); assert(nthset(0b0000’1101’1000’0100’1100’1000’1010’0000, 1) == 0b0000’0000’0000’0000’0000’0000’1000’0000); assert(nthset(0b0000’1101’1000’0100’1100’1000’1010’0000, 3) == 0b0000’0000’0000’0000’0100’0000’0000’0000); assert(nthset(0b0000’1101’1000’0100’1100’1000’1010’0000, … Read more

Standard Deviation for SQLite

You can calculate the variance in SQL: create table t (row int); insert into t values (1),(2),(3); SELECT AVG((t.row – sub.a) * (t.row – sub.a)) as var from t, (SELECT AVG(row) AS a FROM t) AS sub; 0.666666666666667 However, you still have to calculate the square root to get the standard deviation.

Passing a local variable from one function to another

First way is function function1() { var variable1=12; function2(variable1); } function function2(val) { var variableOfFunction1 = val; // Then you will have to use this function for the variable1 so it doesn’t really help much unless that’s what you want to do. } Second way is var globalVariable; function function1() { globalVariable=12; function2(); } function … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)