text:
Q: Linking problems with a category on Scripting Bridge I am trying to write a category over iTunesTrack with associated objects (an NSMutableDictionary and an NSNumber)
#import "iTunes.h"
#import <objc/runtime.h>

@interface iTunesTrack (dictionary)
- (NSMutableDictionary*) getDictionary;
- (NSNumber*) getScan;
- (BOOL)scanTrack:(NSString *)equationString;
@end

This fails:
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_iTunesTrack", referenced from:
      l_OBJC_$_CATEGORY_iTunesTrack_$_dictionary in iTunesTrack+dictionary.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have double checked that the Scripting Bridge framework is added and that the iTunesTrack+dictionary.m file is attached to the target.  Could this be some error with combining Categories with Scripting Bridge?

Update:
If I replace iTunesTrack with SBObject, this works.  I have no idea why, though.

Update 2:
This problem is reproducible:

*

*Create new project

*Add Scripting Bridge Framework and the iTunes.h header file.

*Create new category of iTunesTrack with an arbitrary name

*Ensure that iTunesTrack+name.h imports iTunes.h

*Build

I found this page which describes using NSProxy and NSCache to store iTunesTrack objects.  Would this be a better solution than trying to make a category?

A: Scripting Bridge is quite a mess.
The class iTunesTrack is actually called ITunesTrack under the hood.
I think they were not quite consistent with the leading lowercase i.
This is why they changed it after a while, but probably did not want to do it in the header file, to not change their API.
I don't think there is a way to fix this.
You can, however, just create the category on SBObject.
// The interface can be declared as iTunesTrack
@interface iTunesTrack (Additions)
...
@end

// The category MUST be implemented on SBObject
@implementation SBObject (Additions)
...
@end

Caution
Be aware that the category will be available on every SBObject, so make sure that all properties and methods have a unique interface.

A: You can't put a category on iTunesTrack (or ITunesTrack, or whatever it's called in your header) because that requires the class to exist at link time, and it doesn't: Scripting Bridge creates the target application's classes dynamically at runtime.  (And they have technically arbitrary names, which is why -classForScriptingClass exists.)  It's still possible to add a method to the generated class, but it means mucking about with the runtime, which is generally more trouble than it's worth.  Just put your category method on SBObject and try to be careful.

A: NSAddict's answer pointed the way to do something I've always wanted: implementing debugQuickLookObject for SBObject types to make debugging easier. Here's the category that does iTunesTrack and iTunesArtwork.
//  SBObject+Extensions.h

@import ScriptingBridge;

@interface SBObject (Extensions)

- (id)debugQuickLookObject;

@end

//  SBObject+Extensions.m

#import "iTunes.h"

@implementation SBObject (Extensions)

- (id)debugQuickLookObject
{
    NSString *className = self.className;

    if ([className isEqualToString:@"ITunesTrack"])
    {
        return [self handleITunesTrack];
    }
    else if ([className isEqualToString:@"ITunesArtwork"])
    {
        return [self handleITunesArtwork];
    }

    return [self description];
}

- (NSString*)handleITunesTrack
{
    iTunesTrack *track = (iTunesTrack *)self;

    NSMutableString *s = [NSMutableString new];

    [s appendFormat:@"Title:    %@\n", track.name];
    [s appendFormat:@"Artist:   %@\n", track.artist];
    [s appendFormat:@"Album:    %@\n", track.album];
    [s appendFormat:@"Duration: %f seconds\n", track.duration];

    return s;
}

- (NSImage*)handleITunesArtwork
{
    iTunesArtwork *artwork = (iTunesArtwork *)self;

    NSData *data   = [artwork rawData];
    NSImage *image = [[NSImage alloc] initWithData:data];

    return image;
}

@end

A: You may find the answer in this discussion:
linker command failed with exit code 1 (use -v to see invocation)
Also you can try to clean and then rebuild your project or go to Project -> Build Settings -> Valid Architectures and check whether there's all correct. Some of these advises may help you.


text:
Q: Changing gcc/g++ version causes segfault It seems that changing the version of gcc I use from gcc 4.7.3 to gcc 4.9.2 causes a segfault for my project (after a clean build and run).
In an unfortunate turn of events gdb is broken on the server I am
getting this error on and can't use it for now. Any known changes in gcc itself that could cause this? I suspect the issue is potentially caused by a double free.

A: You should try to use valgrind.
Valgrind is a debugging tool only requiring for your code to be compiled with the -g flag. It's the best way to spot segmentation fault over a program, or any memory leak.
Think about using valgrind options while debugging (it's at the bottom of the valgrind report) something like leak-checkfull (I'm not able to run valgrind right now so I can't tell you exactly what it is).
But whenever I compile my code, I use valgrind with it to check every possible failure. Consider even putting VG in your Makefile rules for more simplicity.

redpajama_set_name: RedPajamaStackExchange


text:
Q: complex irreps is in bijective correspondence with sequences Let $\{a_n\}$ be a sequences of positive integers such that
$$0 \leq a_n\leq p^n - 1,$$
$$a_n \equiv a_{n +1} \bmod p^n \quad \text{for all $n$}$$
Prove that the complex irreps of the group $ U_{p^{\infty}}$  is in bijective correspondence with  sequences $(a_n)$
I know what is the group $ U_{p^{\infty}}.$  I think that it is infinite abelian group. But I can't build its complex irreps. I don't know any what about their order.
I am not sure how to start it.Thanks a lot in advance for any help!

A: Schur's lemma tells us the endomorphism ring of a simple module is a division ring; in particular since the only division algebra over $\Bbb C$ is $\Bbb C$ itself, the (module) endomorphisms of an irreducible representation must be the scalar multiples of the identity map. Therefore if $A$ is an abelian group and $V$ is an irreducible representation of $A$, for each $a\in A$, the action of $a$ is itself $A$-equivariant hence must be a scalar multiple of the identity; it is easy to prove then that $V$ is necessarily one dimensional. If $A$ is abelian, its irreducible representations are identified with dual group $A^\vee$ of homomorphisms $A\to\Bbb C^\times$ (since $\Bbb C^\times\cong{\rm GL}(\Bbb C^1)$).
You want to show the dual group of the Prufer $p$-group $\Bbb Z(p^\infty)$ is the group of $p$-adic integers $\Bbb Z_p$.
We can consider $\Bbb Z_p=\{(a_0,a_1,a_2,\cdots):a_r\equiv a_{r+1}\bmod p^r\}\subseteq\prod_{r=0}^\infty \Bbb Z/p^r\Bbb Z$ (this is the usual route to concretely constructing an inverse limit). We can also say $\Bbb Z(p^\infty)=\Bbb Z[p^{-1}]/\Bbb Z$ (additively).
Suppose $\alpha\in\hom(\Bbb Z(p^\infty),\Bbb C^\times)$. Show that $\alpha(m/p^r)$ must be a $p^r$th root of unity, $m\in\Bbb Z$. Therefore we can always consider $\alpha(1/p^r)=e^{2\pi i\varphi(r)/p^r}$. What is the relation between $\alpha(p^{-r})$ and $\alpha(p^{-(r+1)})$, in particular between $\varphi(r)$ and $\varphi(r+1)$? Can you now construct a coherent sequence of residues mod powers of $p$ out of $\alpha$ which sits inside $\Bbb Z_p$?
Note this goes further than just bijective correspondence; it is an isomorphism of topological groups. This can be checked as well (since $\Bbb Z_p$ and $\Bbb Z(p^\infty)^\vee$ carry group operations and topology.)


text:
Q: put text name user: before id on textbox Inside my form i have an username textbox that has increment id display on
it, My problem is i want to add a text "user:" before the id like on the sample
pic post under. i tried inserting it on value="user: phpcode" but my increment number doesn't increment, hope you can help me in this one.
<button type="button" class="btn" data-dismiss="modal"
        data-toggle="modal" data-target="#exampleModal1" style=" color:#fff; background:#00bcd4" onClick="incrementValue()" value="Increment Value">No</button>

here is my sample code inside a modal:

 New User :

          ×

                <input type="text" class="form-control"  name="username"
                id="username" style="width:45%; margin-top:20px;" readonly  value="user:<?php

           $sql='select max(id)
            from test2';
            $result = mysqli_query($conn,$sql);
            $row = mysqli_fetch_row($result);
            echo $row['0'];
             ?> ">
                Username

div class="text-center mt-2">
           <button type="submit" id="submit" class="btn btn-info"   style="width:98%; ">Log in </button>

</form>

here is my javascript:

A: First of all, you never call your increment function from the code you've attached. You could solve this directly inside your php (if your running a php server, otherwise this won't work... just saying because you don't have a php tag on this question)
So. Are you incrementing this multiple times under "runtime" aka, more times than one. If it's only going to increment one TIME (not steps. (00001 + steps, 1 time)), you could solve this really easy with php.
Here's how to do it in backend:

        <input type="text" class="form-control"  name="username"
        id="username" style="width:45%; margin-top:20px;" readonly  value="user:<?php
        $sql='select max(id)
        from test2';
        $result = mysqli_query($conn,$sql);
        $row = mysqli_fetch_row($result);
        $int = (int)$row['0'] + 1; // <— steps
        $zeros = 5 - strlen(strval($int));
        echo str_repeat("0",$zeros) . $int;
            ?> ">
        Username

A: This is my solution for my question above, just want to share it. :)
<button type="button" class="btn"  style=" color:#fff; background:#00bcd4" onClick="incrementValue()" value="Increment Value">No</button>

               <input type="text" class="form-control"  name="id"  id="id" readonly style="width:45%; margin-top:30px;"  value="<?php

               $sql='select max(id)
                from test2';
                $result = mysqli_query($conn,$sql);
                $row = mysqli_fetch_row($result);
                echo $row['0'];
                 ?> ">
                User's ID

               <input type="text" class="form-control"  name="username"  id="username" style="width:45%; margin-top:20px;" readonly  value="user:00000<?php

               $sql='select max(id)+1
                from test2';
                $result = mysqli_query($conn,$sql);
                $row = mysqli_fetch_row($result);
                echo $row['0'];
                 ?> ">
               Username

My javascript:


text:
Q: High resolution system timer in STM32 I have some software running on an STM32F103 (I'd also like to be able to use the F4) where I'd like to be able to 'timestamp' events (such as interrupts on external pins) to the nearest microsecond (if not better).
As the software will be running for some time I want to use a 64 bit timer, and to me it made sense to use the built in SysTick timer. I have created SysTickMajor (a 64 bit counter) which increments every time SysTick overflows, and a function getSystemTime which combines this counter and the current value of SysTick to get me an accurate 64 bit time:
#define SYSTICK_RANGE 0x1000000 // 24 bit
volatile long long SysTickMajor = SYSTICK_RANGE;

voif onInit(void) {
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
  SysTick_Config(SYSTICK_RANGE-1);
  /* Super priority for SysTick - is done over absolutely everything. */
  NVIC_InitStructure.NVIC_IRQChannel = SysTick_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void SysTick_Handler(void) {
  SysTickMajor+=SYSTICK_RANGE;
}

long long getSystemTime() {
  long long t1 = SysTickMajor;
  long long time = (long long)SysTick->VAL;
  long long t2 = SysTickMajor;
  // times are different and systick has rolled over while reading
  if (t1!=t2 && time > (SYSTICK_RANGE>>1))
    return t2 - time;
  return t1-time;
}

The only problem is this doesn't appear to be 100% accurate - for instance, if I do the following:
bool toggle = false;
while (true) {
  toggle = !toggle;
  LED1.write(toggle);
  long long t = getSystemTime()() + 1000000;
  while (getSystemTime() < t);
}

I won't get a good square wave - occasionally there will be glitches (even though the SysTick interrupt is finished very quickly), because at points the time returned by getSystemTime is completely wrong.

UPDATE: When this happens (I am recording the time value on an interrupt triggered by an external event) I dump the last 3 values to serial. Repeatably I get things like:
>0x278-E2281A
 0x278-E9999A
 0x278-0001E5

>0x5BE-F11F51
 0x5BE-F89038
 0x5BE-0000FB

I've stuck dashes in to depict which bits come from SysTick.
Now just to avoid doubt, I've used the code from starblue below. I've also changed it to use a 32 bit value for SysTickMajor, and I've ANDed out SysTick->VAL, just in case.
It appears that the SysTick_Handler is not preempting the other interrupt!
Now I've checked over this and I did have the Preemption priorities wrong previously, but now I set NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); then set up the interrupts - SysTick preemption priority 0, and the other interrupt is 7.
Is there something else I have to do to get preemption to work?

UPDATE2: I created a tiny test case for this exact issue (SysTick not preempting other interrupts), and have put it here:
STM32 Interrupt Priority (preemption) Problems

So what's wrong with the code above? Is there a better way to get a good high resolution timer? It seems like something obvious that people would want to do but I'm struggling to find examples.

A: As you've discovered, handling counter overflow with an interrupt handler is tricky and race-prone. Even with your priority boost, you'll get the wrong answer if interrupts are disabled while you read the counter. There's a much simpler technique which works if you're not reading the clock from interrupt context (note that I'm using the DWT cycle counter here, which is built into the processor thus fast and simple):
uint64_t last_cycle_count_64 = 0;

// Call at least every 2^32 cycles (every 59.6 seconds @ 72 MHz).
// Do not call from interrupt context!
uint64_t GetCycleCount64() {
  last_cycle_count_64 += DWT->CYCCNT - (uint32_t)(last_cycle_count_64);
  return last_cycle_count_64;
}

If you need to call it from interrupt context (or with a preemptive OS):
volatile uint64_t last_cycle_count_64 = 0;

// Call at least every 2^32 cycles (every 59.6 seconds @ 72 MHz).
uint64_t GetCycleCount64() {
  uint32_t primask;
  asm volatile ("mrs %0, PRIMASK" : "=r"(primask));
  asm volatile ("cpsid i");  // Disable interrupts.
  int64_t r = last_cycle_count_64;
  r += DWT->CYCCNT - (uint32_t)(r);
  last_cycle_count_64 = r;
  asm volatile ("msr PRIMASK, %0" : : "r"(primask));  // Restore interrupts.
  return r;
}

You may need to enable the cycle counter first:
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;  // Set bit 0.

A: Your code has two problems:

*

*You don't know whether the interrupt that increased SysTickMajor happened before or after you read the timer value into time.

*Operations on 64-bit values are not atomic on a 32-bit system.
So the value for SysTickMajor could be updated by the interrupt between reading the two 32-bit words.
I would do it as follows:
major0 = SysTickMajor;
minor1 = SysTick->VAL;
major1 = SysTickMajor;

minor2 = SysTick->VAL;
major2 = SysTickMajor;

if ( major0 == major1 )
{
    time = major1 + minor1;
}
else
{
    time = major2 + minor2;
}

Here you assume that if SysTickMajor changed during the first block of assignments it won't change again in the second block.  (This assumption could be wrong if this code is interrupted during this routine and can't run for a long time.)
See also this question on Stackoverflow.

A: I just found the answer from a very helpful poster on the STM32 forum:
The following isn't correct. SysTick is a 'System Handler', and as such the priority isn't set in this way at all:
  NVIC_InitStructure.NVIC_IRQChannel = SysTick_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // Highest priority
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

It's actually set with:
  NVIC_SetPriority(SysTick_IRQn, 0);

Calling that code instead solves the problem!
So my version of getSystemTime could have had a problem, and starblue's method is nicer than mine - however the actual cause of the problems was the above.
Just thought I'd add one other possible improvement to getSystemTime that I tried as well:
do {
 major0 = SysTickMajor;
 minor = SysTick->VAL;
 major1 = SysTickMajor;
while (major0 != major1);
return major0 - minor;

This will effectively negate the problem where you could (somehow) end up with the SysTick being implemented twice in very quick succession.

A: The previous answers are great. I like this one the most:
do {
 major0 = SysTickMajor;
 minor = SysTick->VAL;
 major1 = SysTickMajor;
while (major0 != major1);
return major0 - minor;

You can optimize it a bit more, since you know that if you have a rollover of SysTickMajor that you're not going to get another rollover "a long time." You should be safe doing this:
major = SysTickMajor;
minor = SysTick->VAL;
if (major != SysTickMajor)
    return SysTickMajor - SysTick->Val;
return major - minor;

The above assumes, of course, that SysTickMajor and VAL are declared as volatile. Several years ago while in a previous job, I discovered that unfortunately the above is still not perfect on all processors. I was using an STM32F407, which has a cache and is pipelined. Sometimes the fetch of the second SysTickMajor would arrive before the VAL even though they were issued in order. Enter the memory barrier (dmb instruction):
major = SysTickMajor;
minor = SysTick->VAL;
__asm__ volatile("dmb");
if (major != SysTickMajor)
    return SysTickMajor - SysTick->Val;
return major - minor;

In my case, I was using a 32-bit TIM2 and a TIM2 rollover ISR which increments the upper 32 bits of my 64-bit cycle counter but I think it should act the same as what you are doing with SysTick.


text:
Q: Invoking Lambdas at Creation In javascript, it is common to use closures and create then immediately invoke an anonymous function, as below:
var counter = (function() {
    var n = 0;
    return function() { return n++; }
}());

Due to strong typing, this very verbose in C#:
Func<int> counter = ((Func<Func<int>>)(() =>
{
    int n = 0;
    return () => n++;
}))();

Is there a more elegant way to go about this type of thing in C#?

A: You don't need the outer lambda in C#, it can be replaced by a simple block.
Directly invoking a lambda is a workaround for the lack of block level variables in Javascript (new versions support block scope using let).
Func<int> counter;

{
     int n = 0;
     counter = () => n++;
}

A: The only thing I can suggest is Func<int> counter could be var counter, but can't think of anything else. Note that counter is still strongly-typed.

See also: var

A: There's not a much nicer way, but the cast is a bit confusing, so I'd prefer this:
Func<int> counter = new Func<Func<int>>(() => { var n = 0; return () => n++; })();

Edit:  As CodeInChaos just asked, the outer lambda seems redundant.
Edit 2:  No, it's not redundant because you want a closure over n.  So either the way above or:
Func<Func<int>> counter = () => { var n = 0; return () => n++; };
int x = counter()();

Edit 3:  Since I am not sure if you want to reuse the counter function, such that it can be reinitialized, which of the two scenarios (or another scenario) do you want:
            Func<Func<int>> counter0 = () => { var n = 0; return () => n++; };

        Console.WriteLine("Counter0:");
        var count0 = counter0();
        for (var i = 0; i < 5; i++)
        {
            Console.WriteLine(count0());
        }

        var count1 = counter0();
        for (var i = 0; i < 5; i++)
        {

            Console.WriteLine(count1());
        }

        Console.WriteLine("Counter1:");
        Func<int> counter1 = new Func<Func<int>>(() => { var n = 0; return () => n++; })();

        for (var i = 0; i < 5; i++)
        {
            Console.WriteLine(counter1());
        }

        for (var i = 0; i < 5; i++)
        {
            Console.WriteLine(counter1());
        }

Output:
Counter0:
0
1
2
3
4
0
1
2
3
4
Counter1:
0
1
2
3
4
5
6
7
8
9

A: is the cast really necessary?  it depends on how you are using the func.
could simply do something like
Func<int> counter = () => { int n; return n++;}

this seems a little strange, though, declaring the variable inside the func and i'm pretty sure it's not really what you intend.


text:
Q: how to test open_basedir setting and make sure it is working correctly I have a VPS using FastCGI (WHM/cPanel). As I understand it, open_basedir must be set using a php.ini file in each user's /home/ directory (E.g.: setting it globally in apache config file will not work).
I want to use open_basedir for improved security, as I recently had a hack that involved traversing through different user's directories
I have added this value to a home directory's php.ini file:
open_basedir = /home/USERNAME/public_html:/usr/lib/php:/usr/local/lib/php:/tmp
What I want to know is, is there a way to test that this is functioning properly? Presumably I would want to try and execute a .php file in another user's directory from within that first user...however I don't know of a good way to test this. Any suggestions would be greatly appreciated.

A: Try listing the contents of a different user's public_html folder:
<?php
print_r(shell_exec('ls /home/$anotheruser/public_html/'));
?>

If open_basedir is configured properly, you will see a directory listing for that folder.


text:
Q: VBA loop through all worksheets in workbook I have tried following VBA code, where I want to run this code for all available worksheets in active workbook, I think I am making small mistake and as I am beginner I am not able to find it out, please help to fix it up
 Sub ProtectFormulas()

 Dim strPassword As String

 Dim ws As Worksheet

 For Each ws In Sheets

 ws.Activate

 .Unprotect

 .Cells.Locked = False

 .Cells.SpecialCells(xlCellTypeFormulas).Locked = True
 .Cells.SpecialCells(xlCellTypeFormulas).FormulaHidden = True

 .Protect AllowDeletingRows:=True

 strPassword = 123456
 ActiveSheet.Protect Password:=strPassword

 Next ws

 End With

 End Sub

Any help would be appriciated by word of thanks.

A: There are 3 issues with your code:

*

*There is no With block.

*The following 2 lines will error if there is no formula in one of the sheets:
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Cells.SpecialCells(xlCellTypeFormulas).FormulaHidden = True

Because if there is no formula then .Cells.SpecialCells(xlCellTypeFormulas) is Nothing and therefore nothing has no .Locked and no .FormulaHidden methods.

*You mix using Sheets and Worksheets. Note that those are not the same!

*

*Sheets is a collection of all type of sheets (worksheets, chart sheets, etc)

*Worksheets is a collection of only type worksheet

If you declare Dim ws As Worksheet and there is for example a chart sheet in your file, then For Each ws In Sheets will error because you try to push a chart sheet into a variable ws that is defined as Worksheet and cannot contain a chart sheet. Be as specific as possible and use Worksheets whenever possible in favour of Sheets.
The following should work:
Option Explicit

'if this is not variable make it a constant and global so you can use it in any procedure
Const strPassword As String = "123456"

Sub ProtectFormulas()
    'Dim strPassword As String
    'strPassword = "123456"  'remove this here if you made it global

    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        With ws
            .Activate 'I think this is not needed
            .Unprotect Password:=strPassword 'unprotect probably needs your password too or this will not work once the worksheet was protected.
            .Cells.Locked = False

            Dim FormulaCells As Range
            Set FormulaCells = Nothing 'initialize (because we are in a loop!)
            On Error Resume Next 'hide error messages (next line throws an error if no forumla is on the worksheet
            Set FormulaCells = .Cells.SpecialCells(xlCellTypeFormulas)
            On Error Goto 0 ' re-enable error reporting! Otherwise you won't see errors if they occur!
            If Not FormulaCells Is Nothing Then 'check if there were formulas to prevent errors if not
                FormulaCells.Locked = True
                FormulaCells.FormulaHidden = True
            End If

            .Protect AllowDeletingRows:=True, Password:=strPassword
        End With
    Next ws
 End Sub


text:
Q: why filtering on extents_tags() is slow Why the following command is slow (5 mins)?
mytable | where extent_tags() contains "20210613" | count

I know this is not the best way to get count , I could have used .show table extents and could have simply calculated sum(RowCount) using summarize operator. But I am just testing. Ideally ADX should be able to search tags across extents and get counts , so it is only metadata search and once it finds correct extent, row count is already stored as part of the extent metadata anyways, so why should it take 5 mins? And by the, the extent(s) I am interested in has the following tag:-
drop-by:20210613
ingest-by:20210613

There is a datetime field in the table which I could have used to filter too , which is what adx ideally recommends in general scenarios and I can guess the reason that min and max of every datetime field in the table is stored in every extent of the table -- but then similarly even tag is stored in every extent. So which method is more efficient , filtering on a datetime field if available or tags?

A: a. you're correct that using .show table T extents where tags contains 'string' | ... would be much more efficient
b. as mentioned in the documentation: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/extenttagsfunction

Filtering on the value of extent_tags() performs best when one of the following string operators is used: has, has_cs, !has, !has_cs.

c. which method is more efficient , filtering on a datetime field if available or tags?
The former, especially when your filter is on a substring, and not on the full content of the tag. Tags are a non-indexed metadata property of shards, and isn't an indexed data column. Also see: https://yonileibowitz.github.io/blog-posts/datetime-columns.html


text:
Q: How to extract non-zero values of a numpy array I have a numpy array and want to extract some values out of it. This is my array:
arr= array([[0, 0, 23, 28],
            [0, 19, 24, 29],
            [0, 20, 25, 30],
            [17, 21, 26, 31],
            [18, 22, 27, 32]])

I want to first sort the non-zero part of it and chage it into:
arr= array([[0, 0, 27, 32],
            [0, 22, 26, 31],
            [0, 21, 25, 30],
            [18, 20, 24, 29],
            [17, 19, 23, 28]])

Then, from the first column, I want to extract the last two rows (18 and 17). In the second column I have four none zero one: it means 2 more nonzero rows compred to previous column. So, I want two upper rows. In the third column I see five non-zero rows which is one row more than the second row, so I want the one row. In last column, the difference of its non-zero rows with the previous one zero, so I do not want any row from it. Finally. I want to have these extracted numbersas a list or numpy array:
result= [17, 18, 21, 22, 27]

I tried the following but it was successful at all:
result=[]
for m in range (len (arr[0,:])):
    for i in range (len (arr[:,m])):
        if arr[i,m]==0 and arr[i+1,m]!=0:
            b= arr[i+1:,m]
            result.append (b)

I appreciate any help in advance.

A: Let's try:
mask = arr != 0

# mask the 0 with infinity and sort
new_arr = np.sort(np.where(mask, arr, np.inf), axis=0)

# replace back:
arr[:] = np.where(mask, new_arr[::-1], 0)

# extract the result
result = arr[np.arange(arr.shape[0]),mask.argmax(axis=1)]


text:
Q: Write a shell script to calculate the number of employees I need to find the count of employees whose salary is less than average salary of all employees.
The file with the employee details will be given as a command line argument when your script will run
example->
Input: File:
empid;empname;salary
100;A;30000
102;B;45000
103;C;15000
104;D;40000

Output:
2
my solution->
f=`awk -v s=0 'BEGIN{FS=":"}{if(NR>1){s+=$3;row++}}END{print s/row}' $file`;

awk -v a="$f" 'BEGIN{FS=":"}{if(NR!=1 && $3<a)c++}END{print c}' $file;

This is what i have tried so far
but output comes out to be
0

A: This one-liner should solve the problem:
awk -F';' 'NR>1{e[$1]=$3;s+=$3}
      END{avg=s/(NR-1);for(x in e)if(e[x]<avg)c++;print c}' file

If you run it with your example file, it is gonna print:
2

explanation:

*

*NR>1 skip the header

*e[$1]=$3;s+=$3 : build a hashtable, and sum the salarays

*END{avg=s/(NR-1); : calc the averge

*for(x in e)if(e[x]<avg)c++;print c :go through the hashtables, count the element, which value < avg and output.

A: Could you please try following.
awk '
BEGIN{
  FS=";"
}
FNR==NR{
  if(FNR>1)
  {
    total+=$NF
    count++
  }
  next
}
FNR==1{
  avg=total/count
}
avg>$NF
'  Input_file  Input_file

A: Your script is fine except it's setting FS=":"; it should be setting FS=";" since that is what is separating your fields in the input.

A: avg=$(awk -F";" 'NR>1 { s+=$3;i++} END { print s/i }' f)
awk -v avg=$avg -F";" 'NR>1 && $3<avg'  f

1) Ignore header and compute Average, avg
2) Ignore header and if salary is less than avg print

A: file=$1
salary=`sed "s/;/ /" $file | sed "s/;/ /" | awk '{print $3}' | tail -n+2`
sum=0
n=0

for line in $salary
do
    ((sum+=line))
    ((n++))
done

avg=$((sum / n))
count=0

for line in $salary
do
    if [ $line -lt $avg ]
    then
         ((count++))
    fi
done

echo "No. of Emp : $count"


text:
Q: Trouble using net_cls control group in tandem with tc for packet filtering I'm having some trouble limiting network bandwidth using the net_cls control group in conjunction with the linux traffic controller (tc).  I think I might just be confused about how I'm writing the filter rules.  I figured the easiest way to manage users network bandwidth would be to use their uid as part of their net_cls control groups classid.  So I set the following rule in my cgconfig file (and keep rebooting the machine).  I also have the proper setup in my cgrules.conf as any limits I impose on other controllers(like memory) are reflected properly.
So say I have a uid of 5004,
group cgroup_demo_cg {

    net_cls {
        net_cls.classid=0x00105004;
#or should it be the hex equivalent of 5004 ?
        #net_cls.classid=0x0010138c;
    }
}

So either way, the next step should be to add some tc stuff.  THe handle is 10 either way so, first create the qdisk:
tc qdisc add dev eth0 root handle 10: htb

then set the class rule:
tc class add dev eth0 parent 10: classid 10:5004 htb rate 4kbit
#or if I had to use the hex value
tc class add dev eth0 parent 10: classid 10:138c htb rate 4kbit

then lastly apply a filter which I think should be the same whether I use the hex value or uid value(5004):
tc filter add dev eth0 parent 10: protocol ip prio 10 handle 1: cgroup

So after I set that up, I expect any network traffic from the user in that cgroup to have its network bandwidth limited by the tc accordingly, however it doesn't appear to be.
If I log in as the user, and set up an ssh session to another one of my machines, and then do a top command(which should send/receive a steady stream of some data), then run the command:
tc -s qdisc ls

I see:
qdisc htb 10: dev eth0 root refcnt 2 r2q 10 default 0 direct_packets_stat 0
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0
qdisc pfifo_fast 0: dev eth1 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
 Sent 1364212 bytes 6045 pkt (dropped 0, overlimits 0 requeues 0)
 backlog 0b 0p requeues 0

Which shows me that nothing was ever added to my qdisk?  :(
Any one have any ideas what I'm doing wrong here?
Cheers!


text:
Q: Consume Workday REST API with oAuth 2.0 in .NET MVC I am trying to call the Workday REST API in my .NET MVC application and am having trouble with the oAuth 2.0 aspect of it. Although in my case I am talking about Workday in particular, I think what I am not understanding can apply to any oAuth 2.0 enabled API. I am trying to use the Authorization Code Grant type.
My understanding of the flow for oAuth 2 is as follows:
1) I send a GET request to an authorize endpoint
2) The user has to log in using their credentials
3) At this point, a response is sent from the API with the Authorization Code Grant in the reponse
4) Now I can make a POST request to exchange the Authorization Code for an Access Token
5) I response is sent back with an Access Token
6) Now I can freely use that Access Token to make GET requests
Conceptually I understand this just fine, but technically, I am getting tripped up moving from step 1 to step 2:
I assume I make the GET request in step 1 from my server (since CORS policy won't allow it to come from my front-end). In that case, I have noticed that the response I get from the api is html with the login page on it. What is a typical process, then, for passing that html to the front-end, having the user login and then moving on to step 3.
Furthermore, there is a field called Redirect URL in the API client configuration, which I assume is where the API will send the response with the Authorization Code Grant, and I also assume should be an action on my controller, but how do I get and consume that response on my page?
I hope this all makes sense.
I can't seem to wrap my head around this.

A: The two authorization flows supported for the Workday REST API are:

*

*implicit grant

*authorization code grant

and each authorization flow can use either type of access token:

*

*bearer token

*MAC token

You will use the authorization flow and the token type that you specified when you registered your client (using the Register API client task on WD).
During the initial authorization request, the current user will be presented with a login page for the tenant, if not already logged in, and will be presented with a consent page, asking to approve or deny access to Workday resources, if using the client for the first time.
From that point onward, your API client will have access to Workday resources as the grant would be approved. You should not have to re-approve the grant.
Basically this would be a one off exercise to create your authorisation flow, and from then on you can use your tokens in the headers of your requests.
Highly recommend that you read through the complete documentation on oAuth for WD Api here https://community.workday.com/rest/oauth
With regards to the redirection uri, you can read more here of what it is and why it is necessary https://www.rfc-editor.org/rfc/rfc6749#section-3.1


text:
Q: Generics Casting interface Base { ... }
class Sub : Base { ... }

class OtherBase<T> where T : Base { ... }
class OtherSub<T> : OtherBase<T> where T : Base { ... }

//...in some class
void Call<T>() where T : OtherBase<Base> { }

//...
Call<OtherSub<Sub>>(); //compile fails...

Seems like when using generics, the compiler won't cast a inner generic type (Base/Sub) in the
generic type (OtherBase/OtherSub). Why does this happen?
Update:
Please also explain the difference between the above and the following (which works)
void Call<T>() where T : Base { }
//...
Call<Sub>();

A: Forbidding this behaviour (known as "generic variance") is necessary because otherwise the following code would compile:
List<string> strlist = new List<string>();
List<object> objlist = strlist;
objlist.Add(42);

We've added a number to a list of strings. Not good. (Incidentally, the code would compile for arrays instead of Lists because Java allowed this for some reason; however, this will raise a runtime exception.)
You can avoid this in your case though:
static void Call<U, T>(T x) where U : Base where T : OtherBase<U> { }

And call it like this:
Call(new OtherSub<Sub());

C# 4.0 furthermore provides generic variance for interfaces. However, their use isn't often necessary.

A: Your issue is linked to a concept called variance/covariance. In fact, if A inherits from B, Class<A> isn't a Class<B>.
See this example:
Class<T> exposes a public method foo(T param)
If Class<A> was a Class<B>, then a method  having a reference to Class<B> as a Class<A> and calling foo(B param) (with a B instance) would be calling foo(A param). And B isn't a A.
In fact, Class<A> can inherit from Class<B> only if T is used as a return value only in Class<T>.
This is enforced in .NET 4 through the out keyword for generics interface. Class<T> could therefore implement IClass<out T>.

A: Konrad has a good advice on how to fix your code. If you wanted to use C# 4's variance, you could do it like this:
interface IOtherBase<out T> where T : Base { }

class OtherBase<T> : IOtherBase<T> where T : Base { }
class OtherSub<T> : OtherBase<T> where T : Base { }

static void Call<T>() where T : IOtherBase<Base> { }

Call<OtherSub<Sub>>() would work then.


text:
Q: onComplete method in Scala's Fututre monod I am learning Future in Scala and have the following code snippet. I am generating random marks based on the first letter in the name.
For the following scenario, I expect a list to be printed by the onComplete method. But it does not print anything.
def randomMark(name:String) = name(0) match {
  case 'R'|'A'|'J'|'S' => Thread.sleep(500); 99
  case  _              => Thread.sleep(500); 80
}

import scala.concurrent._
import concurrent.ExecutionContext.Implicits.global

val returns = Future sequence List( Future(randomMark("Rob")), Future(randomMark("Andy")), Future(randomMark("George")) )

Thread.sleep(550)

returns onComplete { e => { val y1 = e.getOrElse("Error"); println(y1) } }
//This println statement does not execute. I expect a list List(99,99,80) to be printed

Can someone please help me to understand why the functional literal I supply for onComplete method does not execute?
Thanks!

A: Most likely because you need to wait for the result because onComplete is an async operation.
import scala.concurrent.duration._
import scala.concurrent._

def randomMark(name:String) = name(0) match {
  case 'R'|'A'|'J'|'S' => Thread.sleep(500); 99
  case  _              => Thread.sleep(500); 80
}

import scala.concurrent._
import concurrent.ExecutionContext.Implicits.global

val returns = Future sequence List( Future(randomMark("Rob")), Future(randomMark("Andy")), Future(randomMark("George")) )

Thread.sleep(550)

returns onComplete { e => { val y1 = e.getOrElse("Error"); println(y1) } }
println("Waiting futures to be completed")
Await.ready(returns, 5.seconds)
println("Futures to be completed")

Print's out:
Waiting futures to be completed
List(99, 99, 80)
Futures to be completed

Scatie: https://scastie.scala-lang.org/SWv18p8RTtuo7nMNHNHMoQ

A: Since callbacks are executed asynchronously, you'll need to wait for your callback to complete before the program exits. In this case, if you want to wait for an onComplete callback, you need to signal its completion somehow. In the following example I'm using a Promise:
def randomMark(name:String) = name(0) match {
  case 'R'|'A'|'J'|'S' => Thread.sleep(500); 99
  case  _              => Thread.sleep(500); 80
}

import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global

val returns = Future sequence List( Future(randomMark("Rob")), Future(randomMark("Andy")), Future(randomMark("George")) )
val returns: scala.concurrent.Future[List[Int]] = Future(<not completed>)

val p = Promise[Unit]()

returns onComplete { e => { val y1 = e.getOrElse("Error"); println(y1); p.success(()) } }

Await.ready(p.future, 5.seconds)

But, you could, instead use andThen as follows:
def randomMark(name:String) = name(0) match {
  case 'R'|'A'|'J'|'S' => Thread.sleep(500); 99
  case  _              => Thread.sleep(500); 80
}

import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global

val returns =
  Future sequence List( Future(randomMark("Rob")), Future(randomMark("Andy")), Future(randomMark("George")) ) andThen
  { case e => { val y1 = e.getOrElse("Error"); println(y1) } }

Await.ready(returns, 5.seconds)


text:
Q: Defining plugin dependency between subprojects in SBT? EDIT:
Since I put up the bounty, I thought I should restate the question

How can a SBT project P, with two sub-projects A and B, set up B to have a plugin dependency on A, which is a SBT plugin?

*

*Giving P a plugin dependency on A does not work, since A depends on other things in P, which results in a circular dependency graph

*It has to be a plugin dependency, for A is a plugin needed to run Bs test suite.

*dependsOn doesn't work, because, well, it has to be a plugin dependency

    I'd like to know either of

*

*How to do this, or

*Why this is impossible, and what the next best alternatives are.

EDIT: clarified that it's a plugin-dependency, since build-dependency is ambiguous

A: When you have a multi-project build configuration with "project P and two sub-projects A and B" it boils down to the following configuration:
build.sbt
lazy val A, B = project

As per design, "If a project is not defined for the root directory in the build, sbt creates a default one that aggregates all other projects in the build." It means that you will have an implicit root project, say P (but the name is arbitrary):
[plugin-project-and-another]> projects
[info] In file:/Users/jacek/sandbox/so/plugin-project-and-another/
[info]     A
[info]     B
[info]   * plugin-project-and-another

That gives us the expected project structure. On to defining plugin dependency between B and A.
The only way to define a plugin in a SBT project is to use project directory that's the plugins project's build definition - "A plugin definition is a project in <main-project>/project/." It means that the only way to define a plugin dependency on the project A is to use the following:
project/plugins.sbt
addSbtPlugin("org.example" % "example-plugin" % "1.0")

lazy val plugins = project in file(".") dependsOn(file("../A"))

In this build configuration, the plugins project depends on another SBT project that happens to be our A that's in turn a plugin project.
A/build.sbt
// http://www.scala-sbt.org/release/docs/Extending/Plugins.html#example-plugin
sbtPlugin := true

name := "example-plugin"

organization := "org.example"

version := "1.0"

A/MyPlugin.scala
import sbt._

object MyPlugin extends Plugin
{
    // configuration points, like the built in `version`, `libraryDependencies`, or `compile`
    // by implementing Plugin, these are automatically imported in a user's `build.sbt`
    val newTask = taskKey[Unit]("A new task.")
    val newSetting = settingKey[String]("A new setting.")

    // a group of settings ready to be added to a Project
    // to automatically add them, do
    val newSettings = Seq(
        newSetting := "Hello from plugin",
        newTask := println(newSetting.value)
    )

    // alternatively, by overriding `settings`, they could be automatically added to a Project
    // override val settings = Seq(...)
}

The two files - build.sbt and MyPlugin.scala in the directory A - make up the plugin project.
The only missing piece is to define the plugin A's settings for the project B.
B/build.sbt
MyPlugin.newSettings

That's pretty much it what you can do in SBT. If you want to have multi-project build configuration and have a plugin dependency between (sub)projects, you don't have much choice other than what described above.
With that said, let's see if the plugin from the project A is accessible.
[plugin-project-and-another]> newTask
Hello from plugin
[success] Total time: 0 s, completed Feb 13, 2014 2:29:31 AM
[plugin-project-and-another]> B/newTask
Hello from plugin
[success] Total time: 0 s, completed Feb 13, 2014 2:29:36 AM
[plugin-project-and-another]> A/newTask
[error] No such setting/task
[error] A/newTask
[error]          ^

As you may have noticed, newTask (that comes from the plugin from the project A) is available in the (default) root project and the project B, but not in A.

A: As Jacek said, it cannot be done as I would like, as a subproject cannot have a SBT plugin that the root project does not. On the other hand, this discussion on the mailing list contains several alternatives, and would no doubt be useful to anyone who comes across this question in the future.
EDIT: Well, in the end the alternatives mentioned (sbt scripted, etc) were hard and clunky to use. My final solution was to just have a separate project (not subproject) inside the repo that depends on the original project via it's ivy coordinates, and using bash to publishLocal the first project, going into the second project and running its tests
sbt publishLocal; cd test; sbt test; cd ..

I always thought the point of something like SBT was to avoid doing this kind of bash gymnastics, but desperate times call for desperate measures...

A: This answer may include the solution https://stackoverflow.com/a/12754868/3189923 .
From that link, in short, set exportJars := true and to obtain jar file paths for a (sub)project exportedProducts in Compile.

A: Leaving the facts about plugins by side, you have a parent project P with sub-projects A and B. And then you state that A depends on P. But P is a aggregate of A and B and hence depends on A. So you already have a circular dependency between A and P. This can never work.
You have to split P in two parts: The part where A depends on (let's call this part A') and the rest (let's call this P_rest). Then you throw away P and make a new project P_rest consisting of A', A and B. And A depends on A'.


text:
Q: How can I get rmd160 digest of file in python (without subprocess)? I know I can get the sha256 digest of a given file using hashlib.sha256, and could get the rmd160 digest using a subprocess call to openssl rmd160 <myfile>, but is there a python package I can import that provides a method to determine the rmd160 digest?
(rmd160 is a recommended checksum for use in a Macports Portfile [1].)

A: You may use hashlib.new(name) to create hashers from the algorithm name.  My understanding of the documentation (both Python 2 and 3) is that in this case this is delegated to OpenSSL.  OpenSSL supports the names "rmd160" and "ripemd160".
I use
def rmd160(fname):
    BLOCKSIZE = 65536
    h = hashlib.new("rmd160")
    with open(fname, 'rb') as f:
        buf = f.read(BLOCKSIZE)
        while buf:
            h.update(buf)
            buf = f.read(BLOCKSIZE)
    return h.hexdigest()

A: It's not included in the standard library, but pycrypto supports it.
If you're using a unix system with access to a compiler and the required dependencies, you can simply pip install pycrypto. If you're using windows, there are third party pre-built binaries


text:
Q: Let $p$ be prime, and $n < p$. Then $n\times i$ "hits" every residue class for $0 < i < p$. (Searching for clean proof) Intuitively, I'm trying to show that the first $p-1$ multiples of n give every possible remainder after division by p. Or equivalently,
$$ T = \{ \; ni \mod p \; | \; i \in \mathbb{Z}, \; 1 \leq i < p\} $$
$$S = \{ a \; | \; i \in \mathbb{Z},  \; 1 \leq a < p \} $$
are equal.
Showing $T \subseteq S$ is straightforward, but my proof for $ S \subseteq T$ is two handwritten pages long and (even by my standards) convoluted.
This has the feel of well-known theorem, but I can't find it anywhere. Could someone either provide or link to a short/clean proof for the above?

A: Suppose that two numbers fell into the same bin: $a\cdot n\equiv b\cdot n\pmod p$. Then $(a\cdot n-b\cdot n)\equiv 0\bmod p$, so there's some number $c$ with $(a-b)\cdot n=c\cdot p$. Now, can you finish up from here? (This is where it's essential that $p$ is prime.)
Once you know that no two numbers fall into the same bin, then the rest is just an application of the pigeonhole principle: there are $p$ distinct equivalence classes of $a\cdot n\bmod p$ for $0\leq a\lt p$, and there are $p$ distinct representatives $\langle b\rangle$ of those equivalence classes with $0\leq b\lt p$, so the former must cover all the latter.

A: This follows from the fact that $n$ is invertible in the ring $\mathbb{Z_p}$ so you can solve the equation
$$ni = y$$
as
$$i = n^{-1}y$$


text:
Q: Scala check if object is an Option or not I would like to check if an object is an option.
For example:
val foo: Option[String] = Some("foo")
val bar: String = "bar"

I would like a function kind of isOption:
def isOption(value: Any): Boolean = {
     ???
}

And the result will be:
isOption(foo) // true
isOption(bar) // false

A: You can write your function as
def isOption(value: Any): Boolean = {
  value match {
    case x : Option[_] => true
    case _ => false
  }
}

On invoking the function
val foo: Option[String] = Some("foo")
val bar: String = "bar"

you will get an output as
res0: Boolean = true
res1: Boolean = false

A: A short solution would be
value.isInstanceOf[Option[_]]

This also wouldn't obfuscate the fact that you have essentially untyped Any-values and instanceof's flying around in your code, which should be avoided, if possible.


text:
Q: Create a pivot table where the resulting columns are the product of the original columns and rows? This might be impossible to do without a ton of expensive scripting, but I would like to run it by the experts in case I'm missing something. It's hard to explain (because it's nonsensical.. i.e. not my choice), so I'll just give a very simplified example.
My source data sheet is like this...
+----------+-------+------+--------+
|     Date | Time  | Cars | Trucks |
+----------+-------+------+--------+
| 01/01/19 | 08:00 | 2    | 12     |
| 01/01/19 | 12:00 | 4    | 10     |
| 01/01/19 | 20:00 | 6    | 8      |
| 01/02/19 | 08:00 | 8    | 6      |
| 01/02/19 | 12:00 | 10   | 4      |
| 01/02/19 | 20:00 | 12   | 2      |
+----------+-------+------+--------+

.. and I want to have another sheet dynamically display it like ...
+----------+---------------+---------------+---------------+
|          | 08:00         | 12:00         | 20:00         |
+----------+------+--------+------+--------+------+--------+
|          | Cars | Trucks | Cars | Trucks | Cars | Trucks |
+----------+------+--------+------+--------+------+--------+
| 01/01/19 | 2    | 12     | 4    | 10     | 6    | 8      |
| 01/02/19 | 8    | 6      | 10   | 4      | 12   | 2      |
+----------+------+--------+------+--------+------+--------+

In other words, a column for each time at category combined.
Keep in mind that, in reality, this is a large data set. Also, I have a little bit of flexibility in the headers in the sense that, the two header rows in the output could be one. Something like "Cars 8:00", "Trucks 8:00", "Cars 12:00"... etc
Does anybody know how this could be done with a pivot table? Or some other simple'ish method?
Here's a live version of the same example...
https://docs.google.com/spreadsheets/d/1npQikx3Zwa2QZwDAk8IxyawYw2hkeYpPe9Nh4ImkZAE/edit?usp=sharing

A: try:
=ARRAYFORMULA({{TEXT(SUBSTITUTE(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(
 QUERY({Source!A2:B, TRANSPOSE(QUERY(TRANSPOSE(Source!C2:D),,999^99))},
 "select Col1,max(Col3) where Col1 is not null group by Col1 pivot Col2"),
 "limit 0", 1)),,999^99)), " "), "1899-12-30", ), "hh:mm"), ""}; {"",
 SPLIT(REPT(Source!C1&" "&Source!D1&" ", COUNTUNIQUE(Source!B2:B)), " ")};
 TRANSPOSE(QUERY(TRANSPOSE(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(QUERY({Source!A2:B,
 TRANSPOSE(QUERY(TRANSPOSE(Source!C2:D),,999^99))},
 "select Col1,max(Col3) where Col1 is not null group by Col1 pivot Col2"),
 "offset 1", 0))&" ",,999^99)), " ", 1, 0)), "where "&JOIN(" or ", "Col"&
 ROW(INDIRECT("A1:A"&COUNTUNIQUE(Source!A2:A)))&" is not null"), 0))})

spreadsheet demo


text:
Q: Is there any possible to achieve dynamic batch size in Spark Streaming? In order to reduce the difficulty of the code, I allow to restart the Spark Streaming system to use new batch size, but need to keep the previous progress (allowing to lose the batch being processed).
If I use checkpoint in Spark Streaming, it can't change all configurations when the application restarts.
So I want to implement this function by modifying the source code, but I don't know where to start. Hope to give some guidance and tell me the difficulty.

A: Since you are talking about the batch size I'm assuming that you are asking about spark streaming and not structured streaming.
There is a way to programmatically set the value for your batch interval, refer this link for documentation.
the constructor of StreamingContext accepts the duration class's object which defines the batch interval.
you can pass batch interval size by hardcoding it in the code, which will require you to build the jar file every time when you need to change batch interval, instead, you can bring it from a config file, this way you don't need to build the code every time.
Note: You have to set this property in the applications's config file, not in the spark's config file.
You can change the config for batch interval and restart the application, this will not cause any problems with respect to checkpointing.
val sparkConf: SparkConf = new SparkConf()
  .setAppName("app-name")
  .setMaster("app-master")

val ssc: StreamingContext = new StreamingContext(sparkConf, Seconds(config.getInt("batch-interval")))

Cheers!!


text:
Q: Find html tag and echo new code between I've been looking into this for some hours now and have read countless posts here on Stackoverflow and through Google. I've also read up on a few PHP methods and am studying up on some Regex but am not sure on the best method. Here's what I'm trying to achieve:
I have some simple title tags in an hgroup like so:
<hgroup>

Title

Subtitle

</hgroup>

Please note, the hgroup may have a class as well.
I need to search my page for the hgroup tag (with the possible class) and add some code on a new line becoming
<hgroup>
  NEW LINE AND TEXT

Title

Subtitle

</hgroup>

I've found a few solutions to find a class or tag but am not sure how to add a new line of code successfully between.

A: With jQuery:
$("hgroup") // note this could be the class name: you pass in a CSS selector
  .prepend( $("").text("New line and text") );

Live example: http://jsfiddle.net/HzY6y/


text:
Q: How do I set a boolean in parameter types for Cucumber? Cucumber allows you to pass int, string, floats as parameter types, is there a way to do it with Booleans?
Given('the property {string} is set to {string}', function (path, value) {
    this.requestBody = this.requestBody || {};
    _.set(this.requestBody, path, value);
});

A: Short answer, no, but I believe you'll find what you need here.
There are multiple way to achieve this and most of them require you to parse a value to boolean inside the Given step. I believe in your case is the value.
Good luck!

A: You can do this neatly by defining a custom parameter type for boolean, which will allow you to use {boolean} in your step expression in the same way as {string}, {float} etc.
step definition file
const { defineParameterType, Given } = require("@cucumber/cucumber");

defineParameterType({
  name: "boolean",
  regexp: /true|false/,
  transformer: (s) => s === "true" ? true : false
});

Given("the property {string} is set to {boolean}", function (path, value) {
  console.log(typeof value); // "boolean"
});

feature file
Given the property "theProp" is set to true


text:
Q: JavaScript - Move caret to next line (simulate down arrow click) in contenteditable div I have got problem. I am trying to make a function which moves caret to the line which is below in contenteditable div and I have no idea how to do that. Let me explain my problem:

function SomeMagicFunction() {

}
#box {
  width: 400px;
  height: 400px;
  border: 1px solid black;
}
<button onclick="SomeMagicFunction();">Move to next line</button>

SomeTextSomeText

SomeTextSomeText

SomeTextSomeText

SomeTextSomeText

SomeTextSomeText

SomeTextSomeText

SomeTextSomeText

SomeTextSomeText

In the above example, after placing the cursor/caret in the first line and pressing the button, the cursor/caret should be in the second line. I don't know how to make this MagicFunction(). So how to do that using JavaScript and/or JQuery? Thanks for help.


text:
Q: plot a seaborn boxplot with month as x-axes with a daily dataset I have a dataset like this:
>>> print(ds.head())

         date     sum
  0  2013-08-31  19.000
  1  2013-09-01  37.000
  2  2013-09-02  10.750
  3  2013-09-03  21.500
  4  2013-09-04  44.125

>>> print(ds.tail())

            date      sum
    1742  2018-08-24  129.875
    1743  2018-08-25  196.375
    1744  2018-08-26  247.000
    1745  2018-08-27  104.125
    1746  2018-08-28  149.250

The dataset contains about 1700 rows with daily data.
I want to plot a boxplot so see the monthly values.
Something like this

I need the months on the x-axes like JAN/FEB/MAR and so on.
I can´t find any working solutions where I can achieve this if I have a daily dataset. I think I have to do data preparation and group the values per month first?
Or how can I program this in an easy and short way?

A: You can use dt.strftime('%b') element and create the month column as follows:
df=pd.DataFrame(np.random.randint(50,1000,365).reshape(-1,1),
                index=pd.date_range('2018-01-01','2018-12-31',freq='D'),
                columns=['sum'])
df.reset_index(inplace=True)
df.columns = ['Date','sum']
df.head()

          Date  sum
0   2018-01-01  984
1   2018-01-02  582
2   2018-01-03  967
3   2018-01-04  503
4   2018-01-05  330

df['month'] = df['Date'].dt.strftime('%b')

Use seaborn.boxplot and pass x='month', y='sum' and data=df as parameter. You will get the desired boxplot.
fig, ax = plt.subplots()
fig.set_size_inches((12,4))
sns.boxplot(x='month',y='sum',data=df,ax=ax)
plt.show()

The plot colors and other parameters are not set as OP's display plot.

A: You can use the function strftime from datetime.
Here is an example:
from datetime import date
import random
import pandas as pd
from seaborn import boxplot

dates = [date.today()]*10
dataSum = [random.randint(1,100) for x in range(10)]

d = {'date': dates, 'sum':dataSum}
df = pd.DataFrame(data = d)

dateData =  [x.strftime('%B') for x in df['date']]
boxplot(dateData, df['sum'])

Resulting Plot

A: Assuming that your DataFrame df contains the two columns "date" and "sum", we need to sort it on the "date" field to have the rows in the right order for the plot otherwise we could see the months in the wrong order. Then we need to create a support column containing the name of the month of each date. That's it, we are ready for the plot.
Here the code:
import pandas as pd
import seaborn as sns

# just an example...
df = pd.DataFrame([["2013-08-31", 19], ["2013-09-01", 37], ["2013-09-02", 10.75]], columns=["date", "sum"])

# sort the rows by date
df.sort_values(by="date", inplace=True)

# create a support series with the name of the month of each row
month_names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
months = df["date"].apply(lambda date: month_names[int(date.split("-")[1])-1])

# plot it
sns.boxplot(months, df["sum"])

I hope it helps.


text:
Q: Подскажите пожалуйста как открыть popover по id если у меня несколько button Когда у меня несколько event и я нажимаю чтоб открыть popover,неправиьлно показывает данные в поповере .
Но когда один event все нормально показывает
  const [anchorEl, setAnchorEl] = React.useState(null);

  const handleOpenPopover = useCallback(
                (e: React.MouseEventHandler<HTMLDivElement>) => {
                  setAnchorEl(e.currentTarget);
                },
                [],
              );

     return (
                  {events?.map((event, index) => {
                      return (
                        <Styled.Event
                          key={`${event.id}:${event.name}`}
                          onClick={handleOpenPopover}>

                          <ShiftPopover
                            start={event.start}
                            end={event.end}
                            name={event.name}
                            id={event.id}
                            onClose={handleCloseModal}
                            anchorEl={anchorEl}
                            open={Boolean(anchorEl)}
                          />
                        </Styled.Event>
                      );
                    })}

        );


text:
Q: MaxRetryError in Python schedules i am getting an error while i have scheduled a job on each 1,2 minutes. As a part of my script on python i am simply logging in on one website and signing off from there.. it runs on first run, however on 2nd run i am getting below given error message:

MaxRetryError: HTTPConnectionPool(host='localhost', port=49827): Max
retries exceeded with url:
/session/4e4a1d00b1e546035e197c2570e65faf/url (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000024CEB931940>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it'))

Can anyone help on this?
i am expecting login on a website after some interval and logout.


text:
Q: ConTeXt lua array entries being doubled I've been trying to write a piece of ConTeXt code that fills in a persistent lua array with variables parsed from the ConTeXt end, but for some reason it appears as though every \question{}{}{} call gets executed twice, resulting in the array having twice total value it should, and being twice as long as it should be. Is this expected behaviour, and I've just not understood how ConTeXt parses lua code, or is there a bug I can't see?
\setuppapersize[A4]
\usepath[Assets]

\startluacode
    userdata = userdata or {}

    qVals={}
    table.reduce = function (list, fn)
        local acc
        for k, v in ipairs(list) do
            if 1== k then
                acc = v
            else
                acc = fn(acc, v)
            end
        end
        return acc
    end

    local sumT = function (a, b)
        return a +b
    end

    function userdata.getQval(weight, question)
        qVals[#qVals+1]=tonumber(weight)
        tot = table.reduce(qVals, sumT)
        context("(" .. weight .. " points) " .. question .. " " .. tot)
    end
\stopluacode

\defineenumeration[questionEnumeration]
[
    text={},
    title=yes,
    titlestyle=bold,
    titleright={},
    titleleft={},
]

\def\getQuestionVal#1#2{%
    \ctxlua{userdata.getQval([==[#1]==], [==[#2]==])}%
}

\def\question#1#2#3{%
    \startquestionEnumeration[title=\getQuestionVal{#1}{#2}]
        \doifmodeelse{key}{\startcolor[red]#3\stopcolor}{\blank[#1*2em]}
    \stopquestionEnumeration
}

\starttext
    %\enablemode[key]

    \question{3}{This is the question}{this is its sol}
    \question{7}{Another question}{another sol}
    \question{5}{and another}{yet another sol}
\stoptext

P.S. I've figured out a work around that uses an incrementing number that gets rounded as the array indexing (thus overwritting duplicates) but I would prefer a true solution if it exists.

A: To get the correct dimensions for the title length when you use the width=fit setting for enumerations or descriptions ConTeXt has to do a trial run in the complete content of the title.
When you have now a case where a value is incremented with the title you have to use the trialtypesetting conditional or mode to prevent the value to be incremented.
\defineenumeration [question] [text=Question ,title=yes]

\definecounter[testcounter]

\starttext

\startquestion[title={Testcounter: \incrementedcounter[testcounter]}]
First question
\stopquestion

\startquestion[title={Testcounter: \incrementedcounter[testcounter]}]
Second question
\stopquestion

\startquestion[title={Testcounter: \iftrialtypesetting\else\incrementedcounter[testcounter]\fi}]
Third question
\stopquestion

\startquestion[title={Testcounter: \doifnotmode{*trialtypesetting}{\incrementedcounter[testcounter]}}]
Fourth question
\stopquestion

\stoptext


text:
Q: How to calculate overall lift in R for Retail Promotion I'm trying to find out which promotion was effective for Retail promotion data.
Data has the following column names:
item_nbr,Promo_Type,sales,units,promo_units,promo_sales,fineline_nbr,dept_subcatg_nbr,dept_category_nbr,dept_catg_grp_nbr,acctg_dept_nbr,year,week
The formula to calculate is :
Overall Lift = Lift in Promoted Item Sales + Halo – Cannibalization – Pull-forward
How do I go about calculating Overall lift(Halo, Cannibalization, Pull forward, lift) and baseline in R?

A: You have to make decisions before your lift calculation is made.
Are you looking for profit lift, unit lift, total sales dollar lift? What increase are you looking to measure?
And choose a baseline...is it the immediately proceeding x number of days before the promotion where  x is the number of promotional days? Is it the number of sales made in the same period last year (without promotion) is it a periodic average (with all promotions removed from the set?
Then you simply take the promotional metric (say $ value in sales) minus the non-promotional baseline/ the non-promotional baseline .
Example: ($15000-$2100)/$2100 or (12 sales - 4 sales)/ 4 sales.
You need to know your data set well enough to sort the specific sales by category and create those two classes of data properly to calculate lift.


text:
Q: How to import data from MS-Access to excel power query using sql statement and vba? In the company that I work, there is a folder with many access database files that are generated by a system. They have all the same structure but different data. I'm trying to build an Excel tool to compare and analyze some of them using power query (connected to workbook datamodel and use DAX as well). People who will use the system are not very familiar with vba, power queries (me neither), or SQL statements. So, what I thought to do is to code a vba function to allow people to select the files they want to analyze and then, update the workbook power queries with this data. The power queries source data should be SQL statements.
I'm using the "Formula" propertie to make all the changes needed (actually, new data source file, append a column with the filename, and append the result for the other data source files (if more than one is selected). The following code works if I'm importing a table but I'm not able to do it using a SQL statement. I've tried to change some Access.Database parameters like using Query="Select XXX" instead of Item="TableXXX" but it didn't work.
I've found some information about using ODBC but I wouldn't like to work with ODBC because, it seems to me, that the tool can result in many connections to handle (open and delete) whenever the user decides to change the data source.
Following there is an example with only the "Formula" propertie for two data source files. I didn't write the loop to build the string strSource because I don't have problems with it. I suppose the problem is to use an SQL statement in Access.Database. Thanks for the help.
strSource = "let
    Fonte = Access.Database(File.Contents("PathName\File01Name.mdb")),
    _TbEx_1 = Fonte{[Schema="",Item="TableExample"]}[Data],
    _TbEx_C1 = Table.AddColumn(_TbEx_1, "Case", each "File01Name", type text),
    Fonte_2 = Access.Database(File.Contents("PathName\File02Name.mdb")),
    _TbEx_2 = Fonte_2{[Schema="",Item="TableExample"]}[Data],
    _TbEx_C2 = Table.AddColumn(_TbEx_2, "Case", each "File02Name", type text),
    _TbExComb = Table.Combine({_TbEx_C1 , _TbEx_C2})
in
    _TbExComb"

ActiveWorkbook.Queries("PwQry01").Formula = strSource
ThisWorkbook.Connections("Qry-PwtQry01").Refresh

Searching on internet, I've found a way of using SQL statement, but the problem becames to combine the connections of different files on the same power query. Following the code that I've found, but I suppose the "Formula" propertie is closer the final answer.
cnString = "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
        "PathName\File01Name.mdb;Mode=Read"

    ThisWorkbook.Connections.Add2 _
        Name:="MyConnect", _
        Description:="Testing connection", _
        ConnectionString:=cnString, _
        CommandText:="SELECT * FROM TableExample", _
        lCmdtype:=XlCmdType.xlCmdSql, _
        CreateModelConnection:=True, _
        ImportRelationships:=True

Being naive, what I'd like to see is something like:
strSource = "let
    Fonte = Access.Database(File.Contents("PathName\File01Name.mdb")),
    _TbEx_1 = Fonte{[Schema="",Query="SELECT XXXXX"]}[Data],
    _TbEx_C1 = Table.AddColumn(_TbEx_1, "Case", each "File01Name", type text),
    Fonte_2 = Access.Database(File.Contents("PathName\File02Name.mdb")),
    _TbEx_2 = Fonte_2{[Schema="",Query="SELECT XXXX"]}[Data],
    _TbEx_C2 = Table.AddColumn(_TbEx_2, "Case", each "File02Name", type text),
    _TbExComb = Table.Combine({_TbEx_C1 , _TbEx_C2})
in
    _TbExComb"

ActiveWorkbook.Queries("PwQry01").Formula = strSource
ThisWorkbook.Connections("Qry-PwtQry01").Refresh

A: It would be much easier to "concatenate" all the data using Access to a single mdb file and use this to do the rest of the work.

A: I followed @Wedge suggestion and used ODBC approach.
To make it work, I've created an ODBC with no ms-access file associated on Windows ODBC Data source.
In Excel, the user selects the files he wants to analyze and this information is strPath() variable.
With a loop, all files are included in Formula property.
Variable tpPQSQLMap is a customized type (I believe could be a dictionary) with strPQNames to the query name and strPQSQL to the SQL statement.
Following the final code
For pq = 1 To ThisWorkbook.Queries.Count
    strSource = ""
    strSrcComb = ""
    For k = 1 To UBound(strPath)
        strSource = strSource + "SourceC" + CStr(k) + "=Odbc.Query(""dbq=" + strPath(k) + ";dsn=MyODBC"", """ + tpPQSQLMap(pq).strPQSQLs + """), " + vbCrLf
        strSrcComb = strSrcComb + "SourceC" + CStr(k) + ","
    Next k
    strSrcComb = Left(strSrcComb, Len(strSrcComb) - 1)
    strSource = "let " + vbCrLf + strSource + "Final = Table.Combine({" + strSrcComb + "}) " + vbCrLf + "in " + vbCrLf + "Final "

    ThisWorkbook.Queries(pq).Formula = strSource
    ThisWorkbook.Connections("Query - " + tpPQSQLMap(pq).strPQNames).Refresh
Next pq


text:
Q: Delay-Load in Windows I am trying to get my head around some code (adapted straight from PyCXX). It is a multiplatform C++ Python wrapper.
EDIT: Original code here.
It appears to be catering for some particular phenomenon that only exists in Windows:
#ifdef PY_WIN32_DELAYLOAD_PYTHON_DLL
:
#else
:
#endif

I will give the complete file listing below, it is quite long.
This PY_WIN32_DELAYLOAD_PYTHON_DLL token doesn't exist within CPython, it is also not defined in PyCXX. Hence I can only imagine PyCXX intends that it is supplied as an optional compiler flag.
What I would like to know is: What is its purpose? What problem is it solving? Why does this mechanism even exist?
Maybe someone who is familiar with Windows programming can figure it out from the code?
I would like to know whether the problem it is solving is still present in modern Windows, as the code is >15 years old.
The key question is: Can I remove it, or replace it with something cleaner?
I would very much like to cut it out; but does it still serve some useful purpose on a modern Windows environment?
Code:
#include "Base.hxx" //"IndirectPythonInterface.hxx"

namespace Py
{

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

#ifdef PY_WIN32_DELAYLOAD_PYTHON_DLL

#   ifndef MS_WINDOWS
#       error "Can only delay load under Win32"
#   endif
#   include <windows.h> // !!! Is it possible we ever want Windows.h but no delay load? If so, this is wrong...

static HMODULE python_dll;

#   define DECLARE_ERROR( THE_ERROR ) \
        static PyObject* ptr__Exc_##THE_ERROR = nullptr;
ALL_ERRORS( DECLARE_ERROR )

static PyObject* ptr__PyNone        = nullptr;
static PyObject* ptr__PyFalse       = nullptr;
static PyObject* ptr__PyTrue        = nullptr;

#   define DECLARE_TYPE( T ) \
        static PyTypeObject* ptr__##T##_Type = nullptr;
ALL_TYPES( DECLARE_TYPE )

static int* ptr_Py_DebugFlag        = nullptr;
static int* ptr_Py_InteractiveFlag  = nullptr;
static int* ptr_Py_OptimizeFlag     = nullptr;
static int* ptr_Py_NoSiteFlag       = nullptr;
static int* ptr_Py_VerboseFlag      = nullptr;

static char** ptr__Py_PackageContext = nullptr;

#   ifdef Py_REF_DEBUG
int* ptr_Py_RefTotal; // !!! Why not static?
#   endif

//--------------------------------------------------------------------------------
class GetAddressException
{
public:
    GetAddressException( const char* _name )
        : name( _name )
    { }
    virtual ~GetAddressException() { }
    const char* name;
};

//--------------------------------------------------------------------------------

#   define GET_PTR( FUNC, RETURN_TYPE ) \
        static FUNC( const char *name ) \
            { \
                FARPROC addr = GetProcAddress( python_dll, name ); \
                if( addr == nullptr ) \
                    throw GetAddressException( name ); \
                \
                return RETURN_TYPE addr; \
            }

GET_PTR( PyObject *             GetPyObjectPointer_As_PyObjectPointer       , *(PyObject **)        )
GET_PTR( PyObject *                    GetPyObject_As_PyObjectPointer       ,  (PyObject *)         )
GET_PTR( PyTypeObject *     GetPyTypeObjectPointer_As_PyTypeObjectPointer   , *(PyTypeObject**)     )
GET_PTR( PyTypeObject *            GetPyTypeObject_As_PyTypeObjectPointer   ,  (PyTypeObject*)      )
GET_PTR( int *                              GetInt_as_IntPointer            ,  (int*)               )
GET_PTR( char **                    GetCharPointer_as_CharPointerPointer    ,  (char**)             )

#   ifdef _DEBUG
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d_D.DLL";
#   else
static const char python_dll_name_format[] = "PYTHON%1.1d%1.1d.DLL";
#   endif

//--------------------------------------------------------------------------------
bool InitialisePythonIndirectInterface()
{
    char python_dll_name[sizeof(python_dll_name_format)];

    _snprintf( python_dll_name, sizeof(python_dll_name_format) / sizeof(char) - 1, python_dll_name_format, PY_MAJOR_VERSION, PY_MINOR_VERSION );

    python_dll = LoadLibraryA( python_dll_name );
    if( python_dll == nullptr )
        return false;

    try
    {
#   ifdef Py_REF_DEBUG
        ptr_Py_RefTotal             = GetInt_as_IntPointer( "_Py_RefTotal" );
#   endif
        ptr_Py_DebugFlag            = GetInt_as_IntPointer( "Py_DebugFlag" );
        ptr_Py_InteractiveFlag      = GetInt_as_IntPointer( "Py_InteractiveFlag" );
        ptr_Py_OptimizeFlag         = GetInt_as_IntPointer( "Py_OptimizeFlag" );
        ptr_Py_NoSiteFlag           = GetInt_as_IntPointer( "Py_NoSiteFlag" );
        ptr_Py_VerboseFlag          = GetInt_as_IntPointer( "Py_VerboseFlag" );
        ptr__Py_PackageContext      = GetCharPointer_as_CharPointerPointer( "_Py_PackageContext" );

#   define ASSIGN_PTR( E ) \
        ptr__Exc_##E    = GetPyObjectPointer_As_PyObjectPointer( "PyExc_" #E );
        ALL_ERRORS( ASSIGN_PTR )

        ptr__PyNone                 = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" );
        ptr__PyFalse                = GetPyObject_As_PyObjectPointer( "_Py_ZeroStruct" );
        ptr__PyTrue                 = GetPyObject_As_PyObjectPointer( "_Py_TrueStruct" );

#   define MAKE_PTR( TYPENAME ) \
        ptr__##TYPENAME##_Type      = GetPyTypeObject_As_PyTypeObjectPointer( "Py" #TYPENAME "_Type" );
        ALL_TYPES( MAKE_PTR )
    }
    catch( GetAddressException &e )
    {
        OutputDebugStringA( python_dll_name );
        OutputDebugStringA( " does not contain symbol " );
        OutputDebugStringA( e.name );
        OutputDebugStringA( "\n" );

        return false;
    }

    return true;
}

//#if 0
//#define Py_INCREF(op) (                         \
//    _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
//    ((PyObject*)(op))->ob_refcnt++)
//
//#define Py_DECREF(op)                           \
//    if (_Py_DEC_REFTOTAL  _Py_REF_DEBUG_COMMA   \
//        --((PyObject*)(op))->ob_refcnt != 0)    \
//        _Py_CHECK_REFCNT(op)                    \
//    else                                        \
//        _Py_Dealloc((PyObject *)(op))
//#endif

void _XINCREF( PyObject* op )
{
    // This function must match the contents of Py_XINCREF(op)
    if( op == nullptr )
        return;

#   ifdef Py_REF_DEBUG
    (*ptr_Py_RefTotal)++;
#   endif
    (op)->ob_refcnt++;

}

void _XDECREF( PyObject* op )
{
    // This function must match the contents of Py_XDECREF(op);
    if( op == nullptr )
        return;

#   ifdef Py_REF_DEBUG
    (*ptr_Py_RefTotal)--;
#   endif

    if (--(op)->ob_refcnt == 0)
        _Py_Dealloc((PyObject *)(op));
}

#else // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//
//    Needed to keep the abstactions for delayload interface
//
// !!! π Py_XDECREF has been deprecated in favour of Py_CLEAR

void _XINCREF( PyObject* op )
{
    Py_XINCREF( op );
}

void _XDECREF( PyObject* op )
{
    Py_XDECREF( op );
}

#endif // PY_WIN32_DELAYLOAD_PYTHON_DLL

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

//
//    Wrap Python-types, type checks, errors, flags, etc as function calls
//

#ifdef PY_WIN32_DELAYLOAD_PYTHON_DLL
#   define IF_DELAYLOAD_ELSE( A, B ) A
#else
#   define IF_DELAYLOAD_ELSE( A, B ) B
#endif

#define _Foo_Check( TYPENAME ) \
    bool _##TYPENAME##_Check( PyObject *pyob )  \
    { \
        return pyob->ob_type == _##TYPENAME##_Type(); \
    }
ALL_TYPES( _Foo_Check )

#define _Foo_Type( TYPENAME ) \
    PyTypeObject* _##TYPENAME##_Type() \
    { \
        return IF_DELAYLOAD_ELSE( ptr__##TYPENAME##_Type, & Py##TYPENAME##_Type ); \
    }
ALL_TYPES( _Foo_Type )

#define _Exc_Foo( E ) \
    PyObject* _Exc_##E() \
    { \
        return IF_DELAYLOAD_ELSE( ptr__Exc_##E, ::PyExc_##E ); \
    }
ALL_ERRORS( _Exc_Foo )

int& _Py_DebugFlag()                    { return IF_DELAYLOAD_ELSE( *ptr_Py_DebugFlag       , Py_DebugFlag ); }
int& _Py_InteractiveFlag()              { return IF_DELAYLOAD_ELSE( *ptr_Py_InteractiveFlag , Py_InteractiveFlag ); }
int& _Py_OptimizeFlag()                 { return IF_DELAYLOAD_ELSE( *ptr_Py_OptimizeFlag    , Py_OptimizeFlag ); }
int& _Py_NoSiteFlag()                   { return IF_DELAYLOAD_ELSE( *ptr_Py_NoSiteFlag      , Py_NoSiteFlag ); }
int& _Py_VerboseFlag()                  { return IF_DELAYLOAD_ELSE( *ptr_Py_VerboseFlag     , Py_VerboseFlag ); }

char* __Py_PackageContext()             { return IF_DELAYLOAD_ELSE( *ptr__Py_PackageContext , _Py_PackageContext ); }

PyObject* _None()                       { return IF_DELAYLOAD_ELSE( ptr__PyNone             , &::_Py_NoneStruct ); }
PyObject* _False()                      { return IF_DELAYLOAD_ELSE( ptr__PyFalse            , Py_False ); }
PyObject* _True()                       { return IF_DELAYLOAD_ELSE( ptr__PyTrue             , Py_True ); }

} // namespace Py

A: On Win32, delay loading is a mechanism to allow a PE file to reference another PE file which is not where the loader expects it at the time that the file is launched, or to gracefully fall back if it's not there at all. It looks to me as if this is catering to a Windows program that is embedding python itself, but doesn't want to have the DLL containing python sitting in PATH.
Some googling further suggests that this is related to avoiding a circularity between python and a module made to be loaded by python.

A: Macros can be defined with pre-processor arguments, that is why you don't see them anywhere. With Microsoft compiler is with the /D argument.
/D has the same effect as the #define directive at the beginning of a source code file, except that /D strips quotation marks on the command line and #define retains them.
http://msdn.microsoft.com/en-us/library/hhzbb5c8.aspx
With gcc is with -D check this reference link:
https://www.daniweb.com/software-development/c/threads/348802/passing-string-as-d-compiler-option
Delayed load is a mechanism to load the library only when it is used instead of the OS doing it before the application launches. It can save precious memory and load time as (depending on code flow) the dll might not be loaded at all.
This code is trying to implement the delayed load by itself if the macro is defined else just go the normal way. Microsoft linker can do the work for you automatically (i.e. You don't need to program anything). Keep in mind this is not a feature of the platform but a linker feature.
Check this reference:
http://en.wikipedia.org/wiki/Dynamic-link_library#Delayed_loading
You can do away with the code and instruct Microsoft linker to add the code for you if you want.
You can do it with the /DELAYLOAD argument, as explained in this article:
http://msdn.microsoft.com/en-us/library/yx9zd12s.aspx
Just make sure you catch the proper exceptions and hooks if the dll is not found.


text:
Q: I changed my godaddy domain's nameservers, but it continues to direct to the old host I've completed creating a website for a client and the time has come for the go-live. They originally had a wix website (wix is a DIY website builder) and had their godaddy domains point to it.
Since wix is hosting the current site, and I've made them a new site, we are ditching wix for a new hosting service (HostGator). I uploaded a simple index.html to the hostgator server (in public_html) and changed the nameservers for their domain. It's been about an hour and the domains still direct me to the wix site.
Does this take time? If so, how long, and how can I speed it up? The website needs to go live tonight. Let me know what information is needed to help address the problem. Thanks in advance.
update: I've checked my DNS Zone File via my godaddy portal and I am seeing a TTL of 1 hour for everything, but nothing under "NS" (see pic). It's been about several hours at this point. Does this mean I've done something wrong in the process?
picture of my dns zone file via godaddy portal:
http://i.imgur.com/1bZfqww.jpg

A: Assuming the changes were all correctly made, not much you can do except wait it out.  See:
http://support.hostgator.com/articles/hosting-guide/lets-get-started/dns-name-servers/propagation-times
http://support.godaddy.com/help/article/1746/what-factors-affect-dns-propagation-time


text:
Q: How to convert LSTM model to linear regression with keras? model = Sequential()
model.add(LSTM(512, input_shape=(None, 1), return_sequences=True))
model.add(Dropout(0.3))

model.add(LSTM(512, input_shape=(None, 1)))
model.add(Dropout(0.3))

model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='rmsprop', metrics=['accuracy'])
model.summary()
hist = model.fit(x_train, y_train, epochs=10, batch_size=16, verbose=2)
p = model.predict(x_test)

I have this code and predict model p. I want to convert p of time series to a linear regression model.
Time series p -> linear regression model.
How can I accomplish this?


text:
Q: Quit LLDB session after a defined amount of time I have a Program written in python for automated testing on mobile devices (iOS & Android). The proper workflow of this program is as follows (for smoke tests):

*

*Deploy executable to USB-connected device (.ipa or .app) using ios-deploy

*Start Application (debugging process) --> writes to stdout.

*Write output into Pipe --> this way it is possible to read the output of the debugging process parallel to it.

*If the searched needle is detected in the output, the device is restarted (this is quite a dirty workaround, I am going to insert a force-stop method or something similar)
My Problem is: When the needle is detected in the output of the debug process, the lldb session is interrupted, but not exited. To exit the lldb session, I have to reconnect the device or quit terminal and open it again.
Is there a possibility to append something like a "time-to-live-flag" to the lldb call to determine how long the lldb session should run until it exits auomatically? Another way I can imagine how to exit the lldb session is to join the session again after the device is restarted and then exit it, but it seems that lldb is just a subprocess of ios-deploy. Therefore I have not found any possibility to get access to the lldb process.

A: There isn't such a thing built into lldb, but presumably you could set a timer in Python and have it kill the debug session if that's appropriate.
Note, when you restart the device, the connection from lldb to the remote debug server should close, and lldb should detect that it closed and quit the process.  It won't exit when that happens by default, but presumably whatever you have waiting on debugger events can detect the debuggee's exit and exit or whatever you need it to do.
Note, if lldb is waiting on input from debugserver (if the program is running) then it should notice this automatically, since the select call will return with EOF.  But if the process is stopped when you close the connection, lldb probably won't notice that till it goes to read something.
In the latter case, you should be able to have lldb react to the stop that indicates the "needle" is found, and kill the debug session by hand.


text:
Q: NoneType object is not callable django admin I have an app in django admin, im trying to make some validations, Transaction model and its a parent for 2 models, FamilyGroup and FamilMember
class Transaction(models.Model):
    chp_reference = models.CharField(max_length=50, unique=True)
    number_of_family_group = models.PositiveSmallIntegerField( null=True)

class FamilyGroup(models.Model):
    name = models.CharField(max_length=10, choices=name_choices)
    transaction =models.ForeignKey(Transaction,on_delete=models.CASCADE,related_name='family_groups')

class FamilyMember(models.Model):
    transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE)
    family_group = models.ForeignKey(FamilyGroup,
                                     on_delete=models.CASCADE,
                                     null=True,
                                      blank=True, related_name='family_members')
    name = models.CharField(max_length=100, null=True, blank=True)
    date_of_birth = models.DateField(null=True, blank=True)

Im trying to make custome validations in the transaction model like this
@property
def clean(self):
    b = FamilyGroup.objects.filter(transaction__id=self.id).count()
    if self.number_of_family_group != b:
        raise ValidationError('worng family')

when im trying to do this im getting an error NoneType object is not callable
Traceback:
Traceback (most recent call last):
  File "E:\15-12\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "E:\15-12\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "E:\15-12\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "E:\15-12\venv\lib\site-packages\django\contrib\admin\options.py", line 607, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "E:\15-12\venv\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "E:\15-12\venv\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "E:\15-12\venv\lib\site-packages\django\contrib\admin\sites.py", line 231, in inner
    return view(request, *args, **kwargs)
  File "E:\15-12\venv\lib\site-packages\django\contrib\admin\options.py", line 1641, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File "E:\15-12\venv\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "E:\15-12\venv\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "E:\15-12\venv\lib\site-packages\django\contrib\admin\options.py", line 1522, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "E:\15-12\venv\lib\site-packages\django\contrib\admin\options.py", line 1558, in _changeform_view
    form_validated = form.is_valid()
  File "E:\15-12\venv\lib\site-packages\django\forms\forms.py", line 180, in is_valid
    return self.is_bound and not self.errors
  File "E:\15-12\venv\lib\site-packages\django\forms\forms.py", line 175, in errors
    self.full_clean()
  File "E:\15-12\venv\lib\site-packages\django\forms\forms.py", line 378, in full_clean
    self._post_clean()
  File "E:\15-12\venv\lib\site-packages\django\forms\models.py", line 404, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "E:\15-12\venv\lib\site-packages\django\db\models\base.py", line 1207, in full_clean
    self.clean()
TypeError: 'NoneType' object is not callable
[02/Feb/2021 18:47:46] "POST /calculator/transaction/31/change/ HTTP/1.1" 500 143966

A: add related_name='something' to model FamilyMember, so you can rewrite your clean method like this:
def clean(self):
    b = self.something.count()
    if self.number_of_family_group != b:
        raise ValidationError('worng family')

also remember to remove @property decorator from your clean method.

hope to solve your problem.


text:
Q: EF 6 Mix Mode Code First and DB First Iam using EF 6 with database first .. and every time I update the scheme : all my editings to the edmx file  (mainly for defining db built in functions) are lost .. but using code first I can add my dbmodelbuilder calls in a separate  file with partial class .. and by that I can also use all the nuget packages that targets code first such as EntityFramework.Functions.
Thanks for helping

A: You can use Code First from database option when you are creating your ADO.net entity data model. This will give you the code first classes that you can edit.
After creating your model you would need to stick to using the code first model otherwise you will need to regenerate your code-first after every database change...
Download the EF tools here.


text:
Q: Mouse Listener not working with a JFrame in Java I'm trying to make a 2D game in Java. I need a way to detect mouse input for player attacks and some other stuff. I already have a working Key Listener in my game but when I tried adding a Mouse Listener the same way I did the Key Listener it doesn't work.
Here is my Mouse Listener class (Just some test codes for now and these line are never output in the console even when spamming my mouse everywhere on the display)
package input;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class MouseInput extends MouseAdapter
{
public MouseInput()
{

}

@Override
public void mouseClicked(MouseEvent e)
{
    System.out.println("Hello");
}

@Override
public void mousePressed(MouseEvent e)
{
    System.out.println("Mouse Pressed");
}

@Override
public void mouseReleased(MouseEvent e)
{
    System.out.println("Mouse Released");
}
}

Also here is my display class where I create a JFrame and I add my canvas, Key Listener and Mouse Listener to it.
package display;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JFrame;

import input.KeyInput;
import input.MouseInput;

public class Display
{
public static JFrame frame;
private Canvas canvas;

private String title;
private int width;
private int height;

private static double currtime = System.nanoTime();
private static double lasttime = 0;
private static double delta = 0;
private static float fps = 30;
private static int tick = 0;

public Display(String title, int width, int height)
{
    this.title = title;
    this.width = width;
    this.height = height;

    createDisplay();
}

private void createDisplay()
{
    frame = new JFrame(title);
    frame.setSize(width, height);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setFocusable(true);

    canvas = new Canvas();
    canvas.setPreferredSize(new Dimension(width, height));
    canvas.setMinimumSize(new Dimension(width, height));
    canvas.setMaximumSize(new Dimension(width, height));
    canvas.setBackground(Color.WHITE);

    frame.add(canvas);
    frame.addKeyListener(new KeyInput()); // Add the keyListener
    frame.addMouseListener(new MouseInput()); // Add the mouseListener
    frame.pack();
    System.out.println(frame.getMouseListeners().length + " mouse listener found"); // This line outputs 1 mouse listener found
    System.out.println(frame.getKeyListeners().length + " key listener found"); // This line outputs 1 key listener found

}

public void update() // Called every frame
{
    frame.requestFocus();
    tick++;
    lasttime = currtime;
    currtime = System.nanoTime();
    delta = (currtime - lasttime) / 1000000000;
    fps = (float) (1 / delta);
    if (tick / getFPS() >= 2)
    {
        tick = 0;
        System.out.println("FPS = " + Math.round(getFPS()));
        try
        {
            System.out.println("Mouse Position = " + frame.getMousePosition().getX()
                    + ", " + frame.getMousePosition().getY());
        }
        catch (Exception e)
        {
            System.out.println("Mouse out of screen. Could not get mouse position (NullPointerException)");
        }
    }
}

public int getWidth()
{
    return width;
}

public int getHeight()
{
    return height;
}

public Canvas getCanvas()
{
    return canvas;
}

public JFrame getFrame()
{
    return frame;
}

public static float getFPS()
{
    return fps;
}
}

I looked through this forum for answer but every answer given did not fix it.
Tell me if you need any more information to help you solve the problem and thanks in advance for helping :D

A: Add the MouseListener to the canvas object that covers the JFrame, and your code will work. Note that as a side recommendation, you shouldn't be mixing AWT with Swing components. Use a JPanel instead of a Canvas object.
Later we may touch on why KeyListeners should usually be avoided, but since that's not the thrust of your question, we can shelve this for now.
e.g.,
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;

@SuppressWarnings("serial")
public class Display2 extends JPanel {
    private int prefW;
    private int prefH;

    public Display2(int prefW, int prefH) {
        this.prefW = prefW;
        this.prefH = prefH;
        MyMouseAdapter myMouseAdapter = new MyMouseAdapter();
        addMouseListener(myMouseAdapter);
        addMouseMotionListener(myMouseAdapter);
    }

    @Override
    public Dimension getPreferredSize() {
        if (isPreferredSizeSet()) {
            return super.getPreferredSize();
        }
        return new Dimension(prefW, prefH);
    }

    private static void createAndShowGui() {
        Display2 mainPanel = new Display2(500, 500);

        JFrame frame = new JFrame("Display");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(mainPanel);
        frame.pack();
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGui();
            }
        });
    }
}

class MyMouseAdapter extends MouseAdapter {
    @Override
    public void mousePressed(MouseEvent e) {
        System.out.printf("Mouse Pressed at: %s%n", e.getPoint());
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.printf("Mouse Released at: %s%n", e.getPoint());
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        System.out.printf("Mouse Dragged at: %s%n", e.getPoint());
    }
}