EzDevInfo.com

typed.js

A jQuery typing animation script. jQuery Animated Typing with Typed.js | by Matt Boldt

Simply typed lambda calculus with failure, in Haskell

I'm a newcomer to Haskell, so apologies if this question doesn't make too much sense.

I want to be able to implement simply typed lambda expressions in Haskell in such a way that when I try to apply an expression to another of the wrong type, the result is not a type error, but rather some set value, e.g. Nothing. At first I thought using the Maybe monad would be the right approach, but I've not been able to get anything working. I wondered what, if any, would be the correct way to do this.

The context of the problem, if it helps, is a project I'm working on which assigns POS (part of speech) tags to words in sentences. For my tag set, I'm using Categorial grammar types; these are typed lambda expressions like (e -> s) or (e -> (e -> s)), where e and s are the types for nouns and sentences respectively. So for example, kill has the type (e -> (e -> s)) - it takes two noun phrases and returns a sentence. I want a write a function which takes a list of objects of such types, and finds out whether there is any way to combine them to reach an object of type s. Of course, this is just what Haskell's type checker does anyway, so it should be simple to assign each word a lambda expression of the appropriate type, and let Haskell do the rest. The problem is that, if s can't be reached, Haskell's type checker naturally stops the program from running.


Source: (StackOverflow)

Assign Object array with Integer elements to Integer array

I searched the internet but didn't found any appropriate solution.

In my application I've got an array of integers. I need to access (assign to) the array via reflection. The application creates an object array that contains Integer elements. Java doesn't allow to assign this Object array to the Integer array.

Is it not possible in Java? My application only knows the Class Object of the Integer array field. The code is dynamically. The type may be an arbitrary type.

private final Integer[] destArray = new Integer[2];

public static void main(final String[] args) throws Exception {
  final ReloadDifferentObjectsTest o = new ReloadDifferentObjectsTest();
  final Object[] srcArray = {Integer.valueOf(1), Integer.valueOf(2)};
  final Field f = o.getClass().getDeclaredField("destArray");
  f.setAccessible(true);

  // first trial
  // f.set(o, srcArray);

  // second trial
  // Object tmpArray = Array.newInstance(f.getType().getComponentType(), srcArray.length);
  // tmpArray = Arrays.copyOfRange(srcArray, 0, srcArray.length);
  // f.set(o, tmpArray);

  // third trial
  Object tmpArray = Array.newInstance(f.getType().getComponentType(), srcArray.length);
  tmpArray = f.getType().getComponentType().cast(Arrays.copyOfRange(srcArray, 0, srcArray.length));
  f.set(o, tmpArray);
}

Source: (StackOverflow)

Advertisements

Why i can't call the Model and ViewData, and Html in the strong typed page?

I created a new strong typed View ,something like this:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
  Inherits="System.Web.Mvc.ViewPage<MiniMain.ViewModel.ArticleViewdata>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%Model %>
</asp:Content>

but when I called the Mode ,Html,Viewdata,then had no intellisense tips.I can't figure it,please tell me how to do this?


Source: (StackOverflow)

Strongly typed List created with wrongly typed data

I have a strongly typed List Arraylist<Byte> and a developer was trying to add primitive byte data, but the result was completely unexpected. A byte[] was added to this list; how is this even possible? Here is a short example that demonstrates the issue in Java 7

public static void main(String[] args) {
    ArrayList<Byte> wrappedBytes;
    byte[] primitiveBytes = new byte[] { (byte) 0x01, (byte) 0x02, (byte) 0x03 };

    wrappedBytes = new ArrayList(Arrays.asList(primitiveBytes));

    Object value1 = wrappedBytes.get(0);
    System.out.println(value1.getClass().getSimpleName());
}

The system says the first value is a byte[] but the list should only contain Byte values.


Source: (StackOverflow)

Java method that takes only objects that inherit from super class

I would like to have a method in a Java class that will allow me to pass only objects that inherit from super class, f.e.:

I have container super class Div:

package org.gwtbootstrap3.client.ui.html;
    public class Div extends ComplexWidget {
        public Div() {
            setElement(Document.get().createDivElement());
        }
    }

I would like to use Div class and its children in the NRowsXNColumns class:

public class NRowsXNColumns extends GenericLayout {
    public NRowsXNColumns(List<T extends Div> containers) {
        // Do something with each container that extends Div class
        for(T extends Div container: containers) {
            container.display();
        }
    }
}

Unfortunately it doesn't compile.


Source: (StackOverflow)

VS2010 makes a copy of .Designer.cs-file

I'm using VS2010 (C#) for a WinForm database program. I've created a dataset, myds, which generates a couple of related files:

  • myds.xsd
  • myds.Designer.cs
  • myds.xsc
  • myds.xss

When I edit the xsd-file in design mode, perhaps just move around a TableAdapter, myds.Designer.cs makes a copy of itself to myds1.Designer.cs. After that I can't compile the program because the all the types and definitions becomes declared twice (they allready exists in the original myds.Designer.cs-file). It's quite annoying having to delete the copy every time I've made minor changes to that file. Why is it doing this, and can I prevent VS2010 from making this copy?


Source: (StackOverflow)

Trouble getting Typed.js blinking cursor inside form input

Using the Typed.js jQuery plugin, I have been trying to get the blinking cursor to appear inside the form input. I have tried messing around with it and even copying examples that I found online exactly, but it still appears outside the form input. Any ideas?

here is a fiddle showing the issue:

http://jsfiddle.net/dunphyben/1pp3x3au/1/

$(function(){
    $(".form-control").typed({
        strings: ["Web Developer", "Graphic Designer", "Mobile Developer", "Road Warrior", "DevOps", "Real Estate Agent", "Accountant", "Product Manager", "CEO"],
        attr: "placeholder",
        typeSpeed: 100
    });
});

Source: (StackOverflow)

Undefined function call lower()

I am getting the following exception in my sqlite query:

The expression contains undefined function call lower()

I've got a very simple SQLite typed dataset in VS2012.

I'm parsing a large amount of data and want to check if a row already exists prior to adding a new row.

I'm using the .select() method to return an array of datarows. If the length of the array is zero I add a new new. Simple!

All has been working well, but I have added a check to prevent duplicate rows being added if the case is wrong. I am storing filenames.

The select statement is:

"lower(FileName) = '" + EscapeFileName(strFileName).ToLower() + "'"

However I get the above error on the lower(FileName). If I remove this is works fine, but obviously the check is not comparable.

The statement works as expected in SQLiteAdmin.


Source: (StackOverflow)

javascript problem with implicitly typed variables

Forgive this novice question (novice in Javascript!).

In a html page I have a set of images with a name and a number: img1 img2 img3... img12... And there is a JS function where I need to iterate from (say) img5 to last img.

If I write this:

function iterateImg(objImgID) {var imgNum = objImgID.replace("img","");
    for (i=imgNum+1;i<20;i++)
    .../...

The variable "i" is treated as a string, and i+1 receive the value "51" if the passed object's ID is img5.

Of course I can still iterate from 1 to n and only perform the desired task when the value of i reaches 6, but that would be an ugly fix.

How can I fix this please? How can I create a variable that will be treated as an integer before I use it as seed? Besides, what would you recommend as best practice?


Source: (StackOverflow)

DAL using typed dataset

Are there any performance issues in using Typed Data Sets as DAL? Is it a recommended approach? I am using it for listing purposes only (repeater). It has paging, sorting functionalities too.


Source: (StackOverflow)

Custom datatable with metadata used for binding to a Gridview?

I'm binding a datatable to a gridview control, and when I format each column I need to format the data based on whether that column has a particular custom attribute. In this case, a column can represent:

  • a text box (in which case I just display the text from the textbox in the gridview),
  • a checkbox (in which case I display "Checked" or "Unchecked" based on whether the column's underlying data value is 1 or 0),
  • a radio button (in which case I display "On" or "Off" based on whether the column's underlying data value is 1 or 0).

The problem is that the column data types are all strings in the untyped data table being bound to the grid, currently. And the binding uses autoGenerateColumns. So:

  1. How do I flag a column as being either a radio, a textbox, or a checkbox?
  2. How do I access that "flag" while binding to the grid to show the text, "Checked/Unchecked", or "On/Off"?

I hope I asked this right. Phew!


Source: (StackOverflow)

typed.js doesn't work for the second attempt

The first attempt to hover div.logo finish successfully and typed.js types the sentence. After that, when hover again on div.logo it doesn't work and doesn't type anything.

    <script type="text/javascript">
    $( ".logo" ).hover(function() {
        $(this).toggleClass("clicked");
        if ($('.logo').hasClass('clicked')){
              $(function(){
                $('.logo').css('background-position','-20vmin center');
                console.log("n");
                  $(".logo h3").typed({
                    strings: ["Phoenix ^250 Programming ^250 Team"],
                    typeSpeed: 75
                  });
              });
        }
        else{
            $('.logo').find( "h3" ).text("");
            $('.logo span').remove();
            $('.logo').css('background-position','center left+1.5vmin');
        }
    });
    </script>

Source: (StackOverflow)

Intergrating both synchronous and asynchronous libraries

Can synchronous and asynchronous functions be integrated into one call/interface whilst maintaining static typing? If possible, can it remain neutral with inheritance, i.e. not wrapping sync methods in async or vice versa (though this might be the best way).

I've been reading around and see it's generally recommending to keep these separate (http://www.tagwith.com/question_61011_pattern-for-writing-synchronous-and-asynchronous-methods-in-libraries-and-keepin and Maintain both synchronous and asynchronous implementations). However, the reason I want to do this is I'm creating a behaviour tree framework for Dart language and am finding it hard to mix both sync and async 'nodes' together to iterate through. It seems these might need to be kept separate, meaning nodes that would suit a sync approach would have to be async, or the opposite, if they are to be within the same 'tree'.

I'm looking for a solution particularly for Dart lang, although I know this is firmly in the territory of general programming concepts. I'm open to this not being able to be achieved, but worth a shot.

Thank you for reading.


Source: (StackOverflow)

Pause code until it's in the browser window

I am using a jquery plugin called 'typed' that types out sentences, one after the other. this is great but I was wondering if it would be possible to pause the code until the text area was visible in the browser window?

As I want people to be able to see the first sentence that is typed, but currently you would miss the first sentence as it's not visible from the top of the page.

This is the page I'm working on: http://jakdesign.webflow.com/

This is the code in the head of the html:

$(document).ready(function( $ ) {
    $("#hero-text").typed({
        strings: ["First sentence.", "Second sentence."],
        typeSpeed: 0
    });
});

This is the plugin: https://rawgithub.com/morr/jquery.appear/master/jquery.appear.js


Source: (StackOverflow)

Cycle categories with subcategories

1) i have 2 tabs Categories and SubCategories on db with relation 1 to many (im using entity framework)

2) i have to create a vertical menu like this

<ul>
   <li>category 1
    <ul>
       <li>subcategory 1</li>
       <li>subcategory 2</li>      
       <li>subcategory 3</li>
    </ul>
   </li>
</ul>

i think that my problem is here in my function

 Function List_category_subcategory() As List(Of WHAT HERE???????)

        Using db As New DBTestEntities

            Dim q = From cat In db.categories Join subcat In db.subcategories On cat.CategoryID Equals subcat.CategoryID _
            Select New With {cat.CategoryName, subcat.SubCategoryName}

        List_category_subcategory = WHAT HERE???????

        End Using

    End Function

because i dont know what function have to return (maybe a list collection)

After it on my view have to cycle everything

something like that

<ul> 
<%  For Each cat In ??????%>
 <li><a rel='nofollow' href="#"><%=Html.Encode(cat.CategoryName)%></a>
            <ul>
            <% For Each subcat In ???????%>          
            <li><%=Html.Encode(subcat.SubCategoryName)%></li>
            <% Next%>
            </ul>
</li>
<% Next%>
</ul>

Source: (StackOverflow)