EzDevInfo.com

flow.js

A JavaScript library providing multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API.

Dissecting a line of (obfuscated?) Python

I was reading another question on Stack Overflow (Zen of Python), and I came across this line in Jaime Soriano's answer:

import this
"".join([c in this.d and this.d[c] or c for c in this.s])

Entering the above in a Python shell prints:

"The Zen of Python, by Tim Peters\n\nBeautiful is better than ugly.\nExplicit is
better than implicit.\nSimple is better than complex.\nComplex is better than 
complicated.\nFlat is better than nested.\nSparse is better than dense.
\nReadability counts.\nSpecial cases aren't special enough to break the rules.
\nAlthough practicality beats purity.\nErrors should never pass silently.
\nUnless explicitly silenced.\nIn the face of ambiguity, refuse the temptation to
guess.\nThere should be one-- and preferably only one --obvious way to do it.
\nAlthough that way may not be obvious at first unless you're Dutch.\nNow is 
better than never.\nAlthough never is often better than *right* now.\nIf the 
implementation is hard to explain, it's a bad idea.\nIf the implementation is
easy to explain, it may be a good idea.\nNamespaces are one honking great idea 
-- let's do more of those!"

And so of course I was compelled to spend my entire morning trying to understand the above list... comprehension... thing. I hesitate to flatly declare it obfuscated, but only because I've been programming for just a month and a half and so am unsure as to whether or not such constructions are commonplace in python.

this.s contains an encoded version of the above printout:

"Gur Mra bs Clguba, ol Gvz Crgref\n\nOrnhgvshy vf orggre guna htyl.\nRkcyvpvg vf orggre guna vzcyvpvg.\nFvzcyr vf orggre guna pbzcyrk.\nPbzcyrk vf orggre guna pbzcyvpngrq.\nSyng vf orggre guna arfgrq.\nFcnefr vf orggre guna qrafr.\nErnqnovyvgl pbhagf.\nFcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.\nNygubhtu cenpgvpnyvgl orngf chevgl.\nReebef fubhyq arire cnff fvyragyl.\nHayrff rkcyvpvgyl fvyraprq.\nVa gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.\nGurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.\nNygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.\nAbj vf orggre guna arire.\nNygubhtu arire vf bsgra orggre guna *evtug* abj.\nVs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.\nVs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.\nAnzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"

And this.d contains a dictionary with the cypher that decodes this.s:

{'A': 'N', 'C': 'P', 'B': 'O', 'E': 'R', 'D': 'Q', 'G': 'T', 'F': 'S', 'I': 'V', 'H': 'U', 'K': 'X', 'J': 'W', 'M': 'Z', 'L': 'Y', 'O': 'B', 'N': 'A', 'Q': 'D', 'P': 'C', 'S': 'F', 'R': 'E', 'U': 'H', 'T': 'G', 'W': 'J', 'V': 'I', 'Y': 'L', 'X': 'K', 'Z': 'M', 'a': 'n', 'c': 'p', 'b': 'o', 'e': 'r', 'd': 'q', 'g': 't', 'f': 's', 'i': 'v', 'h': 'u', 'k': 'x', 'j': 'w', 'm': 'z', 'l': 'y', 'o': 'b', 'n': 'a', 'q': 'd', 'p': 'c', 's': 'f', 'r': 'e', 'u': 'h', 't': 'g', 'w': 'j', 'v': 'i', 'y': 'l', 'x': 'k', 'z': 'm'}

As far as I can tell, the flow of execution in Jaime's code is like this:
1. the loop c for c in this.s assigns a value to c
2. if the statement c in this.d evaluates to True, the "and" statement executes whatever happens to be to its immediate right, in this case this.d[c].
3. if the statement c in this.d evaluates to False (which never happens in Jaime's code), the "or" statement executes whatever happens to be to its immediate right, in this case the loop c for c in this.s.

Am I correct about that flow?

Even if I am correct about the order of execution, this still leaves me with a ton of questions. Why is <1> the first thing to execute, even though the code for it comes last on the line after several conditional statements? In other words, why does the for loop begin to execute and assign value, but then only actually return a value at a later point in the code execution, if at all?

Also, for bonus points, what's with the weird line in the Zen file about the Dutch?

Edit: Though it shames me to say it now, until three seconds ago I assumed Guido van Rossum was Italian. After reading his Wikipedia article, I at least grasp, if not fully understand, why that line is in there.


Source: (StackOverflow)

How do packages with multiple files work in golang?

This repo has 3 go files all begin with "package lumber". To use this package, I'm supposed to put this in my GOROOT and simply

import lumber

in my program. How do variables and types in this package connect with each other across multiple files? How does the go compiler know which file to begin reading first?

In case I want to read the package, where should I begin reading to understand the package? What exactly is the flow of things here?


Source: (StackOverflow)

Advertisements

What are the benefits of OCaml as a programming language behind Hacklang and Flow?

Recently, Facebook announces Flow, a static type checker for JavaScript, which is implemented mainly in OCaml (https://code.facebook.com/posts/1505962329687926/flow-a-new-static-type-checker-for-javascript/).

Hacklang (PHP with static type checker) is also mainly written in OCaml. So, I wonder that what are the distinctive benefits of OCaml for making a static type checker?


Source: (StackOverflow)

Need explanations for Linux bash builtin exec command behavior

From this link I get the following about exec bash builtin command:

If command is supplied, it replaces the shell without creating a new process.

Now I have the following bash script:


#!/bin/bash
exec ls;
echo 123;
exit 0

This executed, I got this:

cleanup.sh ex1.bash file.bash file.bash~ output.log //files from the current directory

Now, if I have this script:


#!/bin/bash
exec ls | cat
echo 123

exit 0

I get the following output:


cleanup.sh
ex1.bash
file.bash
file.bash~
output.log
123

My question is:

If when exec is invoked it replaces the shell without creating a new process, why when put | cat, the echo 123 is printed, but without it, it isn't. So, I would be happy if someone can explain what's the logic of this behavior.

Thanks.

EDIT: After @torek response, I get an even harder to explain behavior:

1.exec ls>out command creates the out file and put in it the ls's command result;

2.exec ls>out1 ls>out2 creates only the files, but do not put inside any result. If the command works as suggested, I think the command number 2 should have the same result as command number 1 (even more, I think it should not have had created the out2 file).


Source: (StackOverflow)

Webflow in php language

I recently developed a web application in Java EE with Spring framework. I also used the Spring webflow project to define my flow (a strict navigation that user must follow to access certain pages, eq: the shopping cart in ecommerce website).

I'm now on PHP web project. And I want to know if there is any equivalent to SpringWebflow in php (framework or not). Otherwise what's the best practices (eq: to design an shopping cart application) in php ?


Source: (StackOverflow)

create an object before the super call in java

Considering that simple java code which would not work:

public class Bar extends AbstractBar{

    private final Foo foo = new Foo(bar);

    public Bar(){
        super(foo);
    }
}

I need to create an object before the super() call because I need to push it in the mother class.

I don't want to use an initialization block and I don't want to do something like:

super(new Foo(bar)) in my constructor..

How can I send data to a mother class before the super call ?


Source: (StackOverflow)

Execution flow in MVC

I am trying to learn MVC in detail, and I am wondering whats the exact functional flow internally, in the sense of which functions(important functions) are called and what they does when the application starts and which function are called apart from the controller actions that we write in our application as we proceed.

Help in this regard will be much appreciated. Please do suggest some good resources as well if you found any in this regard.

Thanks!


Source: (StackOverflow)

Computing Min-Cut of a Graph with No Reverse Edges

I know you can use a Max-Flow algorithm like Ford-Fulkerson and find a Min-Cut with the Max-Flow/Min-Cut theorem. However, this is not exactly the type of Min-Cut I need to compute.

I want to find the Min-Cut of graph G into sets S and T, where there are no edges from T to S.

This example graph finds a min-cut (of magnitude 250), but the result has an edge from T to S (the red one).

enter image description here

Does anyone know if there's an existing algorithm to solve this? Or if there's a way to modify my flow network so I can use something like Ford-Fulkerson?


Source: (StackOverflow)

How should I write flow-chart-like code? Or should I use something like Windows Workflow Foundation?

I'm investigating the how best to develop/code a flow-chart like scenario.

For example, given the following diagram I could write the pseudo-code beneath it to satisy the requirements. However, as the flow chart changes, this would become difficult to maintain. Also, there's a fair amount of duplication which, again, would only get worse when the flow-chart becomes more complex.

Is the problem I'm trying to solve exactly what Windows Workflow foundation is for? Or would that be too heavy-handed an approach for the task at hand?

Perhaps there is an obvious solution I'm overlooking? Thanks for your help!

(P.S. I should mention that I'm looking for a .NET based solution)

alt text

..and the pseudo code...

Public Function Inbox() as Result

    If IsItImportant() Then
        If IsItUrgent() Then
            If IsItBestUseOfMyTime() Then
                If WillItTakeMoreThan15Mins() Then
                    Return Result.ProjectList
                Else
                    If CanDoItNow() Then
                        Return Result.Now
                    Else
                        If DoesItHaveDeadline() Then
                            Return Result.Calendar
                        Else
                            Return Result.NextAction
                        End If
                    End If
                End If
            Else
                Return Result.Delegate
            End If
        Else
            If IsItActionable() Then
                If IsItBestUseOfMyTime() Then
                    If WillItTakeMoreThan15Mins() Then
                        Return Result.ProjectList
                    Else
                        If CanDoItNow() Then
                            Return Result.Now
                        Else
                            If DoesItHaveDeadline() Then
                                Return Result.Calendar
                            Else
                                Return Result.NextAction
                            End If
                        End If
                    End If
                Else
                    Return Result.Delegate
                End If
            Else
                If IsItReferenceMaterial() Then
                    Return Result.File
                Else
                    Return Result.Trash
                End If
            End If
        End If
    Else
        If IsItWant() Then
            Return Result.Someday
        Else
            Return Result.Trash
        End If
    End If

End Function

Source: (StackOverflow)

flow and mortar transition with shared components

I'm wondering if it is possible to make screens transition animation like Activity transition with shared components as it is frequently used in Android Lollipop and Material design. Thanks.


Source: (StackOverflow)

How do I make text flow through 2 rows of 2 columns using css3?

At the moment I've got a div which is 1024px wide.

In that box are two CSS3 columns with text flowing automatically from one to the next.

However, I want to restrict the height of these two columns to 700px - once they are full I want 2 more columns with the same height to appear underneath them.

Is this possible?


Source: (StackOverflow)

App flow with AccountManager

I've been struggling for a while with my app structure. And it really seems like this structure give me a lot of pain in the developing of other features. So before going further I'd like to have some advice and see if I'm doing something wrong here.

My app's purpose is to connect to a server, I use the AccountManager mechanism to create an account on the device and store a token which is supposed to be used to request data from the server. In the creation of the account, everything is fine. (It works as well from the device settings -> add an account)

It goes like this :

MainActivity is the activity that, when you launch the app, check if you have an account. If you have an account, I get the token in a static variable so every fragment in the MainActivity can access it. (Supposed to work but doesn't) Else, I create an intent with LoginActivity to create an account on the device. The problem is that my fragments can't get this token because, as i'm recovering the token in a thread using AccountManager.getAuthToken(), the fragments are created before this token is recovered. And therefore i can't request data from my server.

Which led me to think that my app structure might not be that good. So I was thinking, "What if I do like so?" :

  • The user launches the app
  • MainActivity act like a bootstrap which check for account and get token if there's an account on the device but do not generate any kind of view like the current version.
  • MainActivity either redirect to LoginActivity or ContentActivity (let's call it that way, an activity that's supposed to use my token to populate data in my ListViews)

That way lets me think that MainActivity will have the token to pass but I'm not sure it's ideal in terms of UX. (Gotta wait for token before accessing a content). I'm open to every suggestion at this point since I'm really stuck.

Thanks !

Update 1:

It's more of a login/registration app logic than handling AccountManager. I've managed to make them work but I just really struggle with the "best practice" app logic structure so I don't run into many other problems because of it (as I don't really have the time). All I need is a diagram or something to show me a "best practice" example to make my app works the way I explained above. I also ran into a problem because when I start the MainActivity it checks for an account and if not it launches LoginActivity but if I press back, i can see MainActivity (unfilled).


Source: (StackOverflow)

How to run a flow once, automatically when starting mule?

I have a java class that creates a clean MongoDB database with seeded collections. It automatically identifies if the database is missing and creates it. I would like to run this when I start MuleEsb. This way I don't need to remember to invoke it before I start mule. I was hoping to put it inside a flow and run that flow once, automatically when mule starts up.

Is there a way to do this one-time operation when mule starts?

--- Update ---

As per the conversation below I added the following to my mule config and the flow is automatically triggered.

<quartz:connector name="Quartz" validateConnections="true"/>

<flow name="testService1">
    <quartz:inbound-endpoint name="runOnce" repeatCount="0" repeatInterval="1" jobName="job1" connector-ref="Quartz">
        <quartz:event-generator-job>
            <quartz:payload>foo</quartz:payload>
        </quartz:event-generator-job>
    </quartz:inbound-endpoint>

    <logger message="INBOUND HEADERS = #[headers:inbound:*]" level="WARN"/>
</flow>

Source: (StackOverflow)

Is there a tool for Django project structure/information flow visualization?

I would like to be able to view the structure of my Django project, i.e. which urls point to which views, which views point to which templates, which css files are included in which templates etc.

I know about the great model visualization tool in Django command extensions, but I need a different tool that is able to visualize links between:

  1. Urls and views;
  2. Views and templates;
  3. Templates and other templates (via {% extends %}, {% include %} and custom template tags);
  4. Templates and static files (css, js, images).

Are there any?


Source: (StackOverflow)

Optimal selection election algorithm

Given a bunch of sets of people (similar to):

[p1,p2,p3]
[p2,p3]
[p1]
[p1]

Select 1 from each set, trying to minimize the maximum number of times any one person is selected.

For the sets above, the max number of times a given person MUST be selected is 2.

I'm struggling to get an algorithm for this. I don't think it can be done with a greedy algorithm, more thinking along the lines of a dynamic programming solution.

Any hints on how to go about this? Or do any of you know any good websites about this stuff that I could have a look at?


Source: (StackOverflow)