EzDevInfo.com

unfold

Unfolding the Box Model — interactive slides exploring CSS 3D Transforms Unfolding the Box Model: Exploring CSS 3D Transforms a short presentation demonstrating the exciting potential of css 3d transforms, a web standard you can use today :)

How to set the default to unfolded when you open a file?

In my .vimrc I've put set foldmethod=syntax to enable folding of methods etc. However, I don't like the default that everytime I open a file, the whole thing is folded. Is there a way to enable foldmethod, yet have files unfolded when I open them?


Source: (StackOverflow)

Google Image Search : Unfolding image details effect with jquery?

I just noticed the nice "new" unfolding effect on Google Image Search when you click on an image. Id like to implement that into my project. Im sure there are already jquery plugins which will do just that. Yet I dunno how this effect may be called in order to do a proper search.


Source: (StackOverflow)

Advertisements

C#: Image unfolding to a rectangle

I need an advice in image processing. I have WF application coded in C# which finds me a coordinates by given parameters and based on this coordinates I would like to crop the image to a circle and unfold this circle to a rectangle.

So just to summarize my questions - How should I correctly crop the image in pictureBox to a circle (ellipse) image and how to unfold this circle to a rectangle?

I hope I described my problem well and I will be very grateful for every advice about how should I continue.


Source: (StackOverflow)

How to do unfolding RFC 822

I am trying to write a vCard Parser and am having trouble unfolding lines. As you can see here: http://www.faqs.org/rfcs/rfc822.html look for "unfolding" it says that all the following are valid:

Long string<return>
<tab>continue

Long string<return>
<tab>(n*<tab>)continue

Long string<return>
<space>continue

Long string<return>
<space>(n*<space>)continue

How do I unfold this? Is there a regex for this? I am using PHP if a class has been written I will use that :)


Source: (StackOverflow)

How to create folding/unfolding text block in email message

Please, advise. How to create a folding unfolding block of text in email message? Please, give me some simple code. I use Thunderbird if it's matters.


Source: (StackOverflow)

Unfolding STL file to 2d

I am using this php script http://schmidtcds.com/files/stlvolume.txt to parse my STL files but i am having some problem achieving my goals perhaps someone can give me some advice .

1) I will like to re triangulate the stl file to add in equilateral triangles with a constant edge size (divide bigger triangles if necessary ).

2) i will like to unfold the result to 2d coordinates not necessarily for paper craft i just need to flatten the end 3d stl in UV coordinates .

I really don't have any idea of where to start i am completely new to stl.

Thanks


Source: (StackOverflow)

Array de-aggregation with repetition in mongodb

I'd like to de-aggregate a mongo collection that has one record, with a single large, large list inside, to instead be represented as many records in another collection. For the variables in the record that are not contained in the long array, this will mean repeating the top levels, above the arary, into each new record as it's copied to the new collection.

What I have is this:

> db.current.showOne()
{"name" : "thing",
"othervar" : 1,
"longcollection" : [
                    {"first": 1,
                     "second":2},
                    {"first": 3,
                     "second":4},
                    {"first": 5,
                     "second":6},
                    ... etc...
                    {"first": 10000,
                     "second":10001}
                    ]
}

What I would like is this:

> db.new.find().limit(5000).pretty()
{"name" : "thing",
"othervar" : 1,
"longcollection" :
                    {"first": 1,
                     "second":2}
},
{"name" : "thing",
"othervar" : 1,
"longcollection" :
                    {"first": 3,
                     "second":4}
},
{"name" : "thing",
"othervar" : 1,
"longcollection" :
                    {"first": 5,
                     "second":6}
},

{"name" : "thing",
"othervar" : 1,
"longcollection" :
                    {"first": 7,
                     "second":8}
}

..etc.

The information unique to each record is in the "longcollection" variable, which is now a dictionary, rather than an array. The other information, on the same level as "longcollection", rather than inside it, is repeated for all new records.

I think this is kind of an unwrap, or unwind. What is the syntax combination of copyTo() and unwrap/aggregation that would get me here? I'm still kind of new on the javascript and aggregation sides of mongodb.


Source: (StackOverflow)

Generating list of iterations on own output in Python

Sorry for what seems like a basic question, but I could not find it anywhere. In Python 2, I would like to apply a 1-variable function to its own output storing the list of all steps, i.e. if f(x) returns x*x then iterating from 2, i need to get

[2, 4, 16, 256, 65536, ...]

Ideally, I would need to pass in my function f, the first input 1, and the number of iterations I would like to keep.

I guess this is, in some sense, the opposite of reduce and somewhat similar to unfold from functional programming.

A naive way to do this is to write

out = [2] for x in xrange(5): out.append(f(out[-1]))

What is a good Pythonic way to do this? Thank you very much.


Source: (StackOverflow)

Weird couldn't match type error

I have simple one line function:

revRange :: (Char,Char) -> [Char]
revRange t = unfoldr (\b -> if b == (pred (fst t)) then Nothing else Just (b, pred b)) (snd t)

It works well:

*Main Data.List> revRange ('a', 'f')
"fedcba"

Then I want to extract unfoldr lambda as unique function:

revRange :: (Char,Char) -> [Char]
revRange t = unfoldr fun t
fun t = (\b -> if b == (pred (fst t)) then Nothing else Just (b, pred b)) (snd t)

Now, I have a weird error:

Couldn't match type `Char' with `(Char, Char)'
Expected type: (Char, Char) -> Maybe (Char, (Char, Char))
  Actual type: (Char, Char) -> Maybe (Char, Char)
In the first argument of `unfoldr', namely `fun'
In the expression: unfoldr fun t

Source: (StackOverflow)

Unfold returning the last state of the accumulator

The unfold function in Haskell is very handy to create lists. Its definition is:

unfold :: (b -> Maybe (a, b)) -> b -> [a]

But I would like to get the last value of the accumulator used. A possible implementation is:

unfoldRest :: (b -> Maybe (a, b)) -> b -> ([a], b)
unfoldRest fct ini = go fct ini []
  where
    go f s acc =
      case f s of
        Nothing -> (acc, s)
        Just (a, b) -> go f b (acc ++ [a])

But I was wondering if there wasn't a way to do it with existing functions. In the end this:

countDown 0 = Nothing
countDown n = Just (n, n-1)
unfoldRest countDown 10

will return:

([10,9,8,7,6,5,4,3,2,1],0)

Because the iteration stopped when the accumulator value reached 0.


Source: (StackOverflow)

Unfoldable instance for the cofree comonad

I'm trying to figure out the difference between unfold/coiter from Control.Comonad.Cofree and unfold/ana from Data.Control.Fixedpoint. Hackage libraries are resp. free and recursion-schemes.

Cofree and Fix seem to be cousins, and I'm trying to figure out what is possible with both and what is possible with only one of them.

I could write an instance of Foldable for Cofree so I can apply cata to a free monad obtained from unfold/coiter:

type instance Base (Cofree f a) = f

instance Functor f => Foldable (Cofree f a) where
    project = unwrap

But I couldn't construct an Unfoldable instance:

instance Functor f => Unfoldable (Cofree f a) where
    embed = xembed

xembed :: Functor f => f (Cofree f a) -> Cofree f a 
xembed = undefined

Is it possible at all?


Source: (StackOverflow)

HW: Unfolding a list in a specific way

In Programming in Haskell, Graham Hutton defines an unfold for lists as follows:

unfold :: (b -> Bool ) -> (b -> a) -> (b -> b) -> b -> [a]
unfold p h t x | p x = []
| otherwise = h x : unfold p h t (t x)

Define a function

• listUnfold :: (b -> Bool) -> (b -> a) -> (b -> b) -> b -> [a]

that is similar to the one above but uses unfoldr in its implementation and is non-recursive.

I've been trying for a while to solve the question above but I still can manage to do so (pretty new in Haskell and functional programming in general).

My attempt:

listUnfold :: (b -> Bool) -> (b -> a) -> (b -> b) -> b -> [a]
listUnfold f h t x 
    | f x == True   = []
    | otherwise     = h x : 
        listUnfoldr (\x -> if f x then Nothing else Just ((h x), (t x))) x

In english, if f x is true, return the empty list. Otherwise, use h x as the head and append the results of unfoldr as the tail. Unfoldr takes a list (x:xs) should recurse itself with x as the head and xs as the tail.

p/s: I'm probably doing this very very wrongly.


Source: (StackOverflow)

Deserializing a nested hash from lists of hash keys

I have a string that I would like to "unflatten" or "tree-ify"; that is, I want to go from this:

F=8|A_C=3|A_B=2|D_G_H=11|D_B=2|E=5  

to this:

{
  A => {
    B => 2,
    C => 3,
  },
  D => {
     B => 2,
     G => {
       H => 11,
     },
  },
  E => 5,
  F => 8,
}

My strategy was to process each pipe-delimited field separately and split by the = sign into a key / value pair:

sub unflatten {
    my ($data) = @_;
    my @fields = split /\|/, $data;
    my $result = {};

    for my $datum (@fields) {
            my ($key, $value) = split /=/, $datum;
            $result->{&processline($key)} = $value;
    }
    return $result;
}

I was attempting some recursive magic in the processline function:

sub processline {
    my ($key) = @_;

    my ($first, $rest) = split /_/, $key, 2; # split key into at most 2 parts
    if($rest) {
            return { $first => &processline($rest) }; 
            # if the key is nested, there will be something in $rest
            # so recursively process the smaller $rest, and build up the result hashref
    }
    else {
            return $first;
    }
}

Unfortunately, this doesn't work:

my $header = "F=8|A_C=3|A_B=2|D_G_H=11|D_B=2|E=5";
use Data::Dumper;
print Dumper &unflatten($header);

When I do this, I get:

$VAR1 = {
      'F' => '8',
      'HASH(0xe9af60)' => '2',
      'HASH(0xe9ae28)' => '11',
      'E' => '5',
      'HASH(0xe9af90)' => '3',
      'HASH(0xe9ae40)' => '2'
    };

Could someone explain the thought process behind a recursive solution, or suggest where my Perl has gone so wrong? Frustratingly, I was able to come up with the inverse of this function (flatten) pretty easily.


Source: (StackOverflow)

How to unfold a recursive function just once in Coq

Here is a recursive function all_zero that checks whether all members of a list of natural numbers are zero:

Require Import Lists.List.
Require Import Basics.

Fixpoint all_zero ( l : list nat ) : bool :=
  match l with
  | nil => true
  | n :: l' => andb ( beq_nat n 0 ) ( all_zero l' )
  end.

Now, suppose I had the following goal

true = all_zero (n :: l')

And I wanted to use the unfold tactic to transform it to

true = andb ( beq_nat n 0 ) ( all_zero l' )

Unfortunately, I can't do it with a simple unfold all_zero because the tactic will eagerly find and replace all instances of all_zero, including the one in the once-unfolded form, and it turns into a mess. Is there a way to avoid this and unfold a recursive function just once?

I know I can achieve the same results by proving an ad hoc equivalence with assert (...) as X, but it is inefficient. I'd like to know if there's an easy way to do it similar to unfold.


Source: (StackOverflow)

typeclass for repetitive actions until fixed point

i noticed a common pattern of executing an action until it stops having certain effects, when one knows that this signifies a fixed point (ie, there can be no future effects). is there a typeclass for this?

is this covered by MonadFix? looking at the code, it seems it would be, but i was scared off by the wiki page "It is tempting to see “recursion” and guess it means performing actions recursively or repeatedly. No."

it also seems to me that fixed points are something like the dual of identities. that is, an identity disappears when combined with a non-identity (0 for (+), 1 for (*), [] for append, etc). whereas a fixed point causes any non-fixed point to disappear under the 'relax' operation below. is there a way to formalize this duality, and is it useful to do so? ie, is there a relationship between MonadPlus and/or Monoid and MonadRelax?

lastly, i notice relax is almost an unfold/anamorphism. would it be better to express it as such?

{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}

import Control.Monad.Loops (iterateUntilM) -- cabal install monad-loops

-- states that relax to a fixed point under step
class Monad m => MonadRelax m s | s -> m where
isFixed :: s -> Bool
step :: s -> m s -- often (not always): step s = return s iff isFixed s

relax :: MonadRelax m s => s -> m s
relax = iterateUntilM isFixed step

Source: (StackOverflow)