EzDevInfo.com

local

An Ajax library that can target local JS code and web workers.

Delete Folder Contents in Python

How can I delete the contents of a local folder in Python?

The current project is for Windows but I would like to see *nix also.


Source: (StackOverflow)

Local Notifications in Android?

can i send local notifications on Android, as i can in iPhone?


Source: (StackOverflow)

Advertisements

How can I test my ssh-keys locally without a server

I want to test my keys in ~/.ssh. I do not have sshd running (Git-Bash@Windows does not provide it). I'd like to test if I still remember the passphrase for my keys.

I found these answers [1], [2], but they do not work for me.

Is there an easy way to verify my ssh keys without an ssh server?


Source: (StackOverflow)

Is there a way to map a UNC path to a local folder on Windows 2003?

I know that I can map a UNC path to a local drive letter. However, I am wondering if there is a way to map a UNC path to a local folder. I have a program that has a specific folder hard coded into the program and I am wanting to try and create a folder with the same name that is mapped to a UNC path so that the data can be accessed from a network share. Is this doable? Specifically this is on a Windows 2003 server.


Source: (StackOverflow)

How to keep the local file or the remote file during merge using Git and the command line?

I know how to merge modification using vimdiff, but, assuming I just know that the entire file is good to keep or to throw away, how do I do that?

I don't want to open vimdiff for each of them, I change want a command that says 'keep local' or 'keep remote'.

E.G: I got a merge with files marked as changed because somebody opened it under windows, changing the EOL, and then commited. When merging, I want to just keep my own version and discard his.

I'm also interested in the contrary: I screwed up big time and want to accept the remote file, discarding my changes.


Source: (StackOverflow)

Android Development: Using Image From Assets In A WebView's HTML

In my app I'm making a basic HTML help document. I wanted my app's logo in the HTML img tag itself, but I don't know how I'd reference to the logo which will be stored in assets.

Is this possible, if so how?

Thanks for the help!


Source: (StackOverflow)

Does it help GC to null local variables in Java

I was 'forced' to add myLocalVar = null; statement into finally clause just before leaving method. Reason is to help GC. I was told I will get SMS's during night when server crashes next time, so I better did it :-).

I think this is pointless, as myLocalVar is scoped to method, and will be 'lost' as soon as method exits. Extra nulling just pollutes the code, but is harmless otherwise.

My question is, where does this myth about helping GC come from? (I was referred to "Java memory books") Do you know any article from 'authorities' which explain it in more depth? Is there possibility this is not a myth, but really helps somehow? If so, how? May nulling local variables cause any harm?

To clarify, method look like this:

void method() {
  MyClass myLocalVar = null;
  try {
    myLocalVar = get reference to object;
    ... do more here ...
  } finally {
    if (myLocalVar != null) {
      myLocalVar.close(); // it is resource which we should close
    }

    myLocalVar = null; // THIS IS THE LINE I AM TALKING ABOUT
  }
}

Source: (StackOverflow)

How to securely save username/password (local)

I'm making a windows application, which you need to log into first.
The account details consist of username and password, and they need to be saved locally.
It's just a matter of security, so other people using the same computer can't see everyone's personal data.
What is the best/most secure way to save this data?

I don't want to use a database, so I tried some things with Resource files.
But since I'm kind of new with this, I'm not entirely sure of what I'm doing and where I should be looking for a solution.


Source: (StackOverflow)

Defining Setter/Getter for an unparented local variable: impossible?

There's a few previous questions on StackOverflow questioning how one goes about accessing local variables via the scope chain, like if you wanted to reference a local variables using bracket notation and a string, you'd need something like __local__["varName"]. Thus far I haven't found even the hackiest method for accomplishing this, and haven't come up with a method after hours of exploiting every trick I know.

The purpose for it is to implement getters/setters on arbitrary unparented variables. Object.defineProperties or __defineGet/Setter__ require a context to be called on. For properties in the global or window contexts you can accomplish the goal of having a setter/getter for direct references to the object.

Object.defineProperty(this, "glob", {get: function(){return "direct access"})
console.log(glob); //"direct access"

Even in my tests with a custom extension I compiled into a modified Chromium that runs prior to any window creation where the context is the actual global context, and even trying to call this directly in the global context crashes my program, I can pull this off without a hitch:

Object.defineProperty(Object.prototype, "define", {
    value: function(name, descriptor){
        Object.defineProperty(this, name, descriptor);
    }
};
define("REALLYglobal", {get: function(){ return "above window context"; }});

And it is then available in all frames created later as a global routed through the specified getter/setter. The old __defineGet/Setter__ also works in that context without specifying what to call it on (doesn't work in Firefox though, the method above does).

So basically it's possible to define get/set guards for any variable on an object, including the window/global context with direct call to the object (you don't need window.propname, just propname). This is the issue with being unable to reference unparented scoped variables, being the only type that can be in an accessible scope but have no addressable container. Of course they're also the most commonly used too so it's not an edge case. This problem also transcends the current implementation of Proxies in ES6/Harmony since it's a problem specifically with being unable to address a local object's container with the language's syntax.

The reason I want to be able to do this is that it's the only barrier to allow overloading of most math operators for use in complex objects like arrays and hashes and deriving a complex resulting value. I need to be able to hook into the setter in cases where a value is being set on an object type I've set up for overloading. No problem if the object can be global or can be a contained in a parent object, which is probably what I'll just go with. It's still useful with a.myObject, but the goal is to make it as transparently usable as possible.

Not only that, but it'd just be really useful to be able to accomplish something like this:

var point3d = function(){
    var x, y, z;
    return {
        get: function(){ return [x, y, z]; },
        set: function(vals){ x=vals[0]; y=vals[1]; z=vals[2]; }
    };
};

(That is similar to ES6's destructuring but has more general applications for implementing functionality attached to getting/setting and not just transporting complex values). Even this basic code will completely fail:

var x = {myname: "intercept valueOf and :set: to overload math ops!", index: 5};
x++; //x is now NaN if you don't implement a setter somehow

I don't care how hacky the solution is, at this point it's just an intense curiosity for me as to whether it can be accomplished, even if it requires breaking every best practice that exists. I've crashed Firefox and Chrome a few hundred times in pursuit of this so far by doing things like redefining/intercepting/modifying Object.prototype.valueOf/toString, Function.prototype Function.prototype.constructor, Function.prototype.call/apply, arguments.callee.caller, etc. with infinite recursion errors and whatnot in attempts to jury rig contexts retroactively. The only thing that I've been able to make work is wrapping basically the whole thing with eval and dynamically building code chunks, which is a bridge too far for me to ever actually use. The only other remotely successful route was in using with combined with pre-defining all local variables on a container, but that's obviously very intrusive on top of the issues with using with.


Source: (StackOverflow)

Android Java; How can I parse a local JSON file from assets folder into a ListView

I'm currently developing a physics app that is supposed to show a list of formulas and even solve some of them (the only problem is the ListView)

This is my main layout

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:measureWithLargestChild="false"
    android:orientation="vertical"
    tools:context=".CatList" >


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/titlebar" >

        <TextView
            android:id="@+id/Title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/app_name"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#ff1c00"
            android:textIsSelectable="false" />

    </RelativeLayout>

    <ListView
        android:id="@+id/listFormulas"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    </ListView>

</LinearLayout>

And this is my main activity

package com.wildsushii.quickphysics;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.view.Menu;
import android.widget.ListView;

public class CatList extends Activity {



    public static String AssetJSONFile (String filename, Context context) throws IOException {
        AssetManager manager = context.getAssets();
        InputStream file = manager.open(filename);
        byte[] formArray = new byte[file.available()];
        file.read(formArray);
        file.close();

        return new String(formArray);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cat_list);
        ListView categoriesL = (ListView)findViewById(R.id.listFormulas);

        ArrayList<HashMap<String, String>> formList = new ArrayList<HashMap<String, String>>();
        Context context = null;
        try {
            String jsonLocation = AssetJSONFile("formules.json", context);
            JSONObject formArray = (new JSONObject()).getJSONObject("formules");
            String formule = formArray.getString("formule");
            String url = formArray.getString("url");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }

        //My problem is here!!
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.cat_list, menu);
        return true;
    }
}

I actually know I can make this without using JSON but I need more practice parsing JSON. By the way, this is the JSON

    {
    "formules": [
    {
      "formule": "Linear Motion",
      "url": "qp1"
    },
    {
      "formule": "Constant Acceleration Motion",
      "url": "qp2"
    },
    {
      "formule": "Projectile Motion",
      "url": "qp3"
    },
    {
      "formule": "Force",
      "url": "qp4"
    },
    {
      "formule": "Work, Power, Energy",
      "url": "qp5"
    },
    {
      "formule": "Rotary Motion",
      "url": "qp6"
    },
    {
      "formule": "Harmonic Motion",
      "url": "qp7"
    },
    {
      "formule": "Gravity",
      "url": "qp8"
    },
    {
      "formule": "Lateral and Longitudinal Waves",
      "url": "qp9"
    },
    {
      "formule": "Sound Waves",
      "url": "qp10"
    },
    {
      "formule": "Electrostatics",
      "url": "qp11"
    },
    {
      "formule": "Direct Current",
      "url": "qp12"
    },
    {
      "formule": "Magnetic Field",
      "url": "qp13"
    },
    {
      "formule": "Alternating Current",
      "url": "qp14"
    },
    {
      "formule": "Thermodynamics",
      "url": "qp15"
    },
    {
      "formule": "Hydrogen Atom",
      "url": "qp16"
    },
    {
      "formule": "Optics",
      "url": "qp17"
    },
    {
      "formule": "Modern Physics",
      "url": "qp18"
    },
    {
      "formule": "Hydrostatics",
      "url": "qp19"
    },
    {
      "formule": "Astronomy",
      "url": "qp20"
    }
  ]
}

I have tried a lot of things and even delete the entire project to make a new one :(


Source: (StackOverflow)

PHP $this variable

I am reading some PHP code that I could not understand:

class foo {
  function select($p1, $dbh=null) {
    if ( is_null($dbh) )
        $dbh = $this->dbh ; 
    return; 
  }

  function get() {
    return $this->dbh; 
  }
}

I can't find $this->dbh ($dbh) declaration from the class. My questions are:

  • What is the value of $this->dbh ?

  • Is it a local variable for function select()?

  • Does $this belong class foo's data member? Why is there no declaration for $dbh in this class?


Source: (StackOverflow)

Can Chrome be made to perform an XSL transform on a local file?

I was looking into xslt and started testing with the examples on w3schools.

However, when I save the xml and xsl in files and try opening them locally, chrome won't perform the xsl transform. It just shows a blank page.

I have added the<?xml-stylesheet type="text/xsl" rel='nofollow' href="style.xsl"> tag to the xml document, and firefox renders it as it is supposed to look. Also, if I look at the files through a web server, chrome displays the file as it is supposed to look.

Is it that chrome has a problem finding the stylesheet information when the link is local? Changing the href to file:///C:/xsl/style.xsl didn't make any difference.

Update: This seems to be a side effect of a security-policy to not treat file:///* as same origin. This makes the following error appear in the console:

Unsafe attempt to load URL file:///C:/xsl-rpg/style.xsl from frame with URL file:///C:/xsl-rpg/data.xml. Domains, protocols and ports must match.


Source: (StackOverflow)

WebView load website when online, load local file when offline

i am actually new to programming in java but i have been following several solutions to my problem here but didn't find one that suits my case and i can't seem to get the code down correctly.

i would like to have a WebView which opens an online page (for example google) when the phone is online and open a local html page when the phone is offline.

at the same time though i want the phone to overwrite the local page when it is online so that the offline local page is always updated to the last time the phone was connected to the internet.

any ideas how this could be done? some simple pointing to the right direction could help.

thanks a lot


Source: (StackOverflow)

How to bind local property on control in WPF

I have two controls on WPF

<Button HorizontalAlignment="Center"
        Name="btnChange"
        Click="btnChange_Click"
        Content="Click Me" />

<Label Name="lblCompanyId"
       HorizontalAlignment="Center"
       DataContext="{Binding ElementName=_this}"
       Content="{Binding Path=CompanyName}" />

As we can see that label is bound to local property(in code Behind), I don't see any value on label when I click button...

Below is my code behind...

public static readonly DependencyProperty CompanyNameProperty =
  DependencyProperty.Register("CompanyName", typeof(string), typeof(Window3), new UIPropertyMetadata(string.Empty));

public string CompanyName {
  get { return (string)this.GetValue(CompanyNameProperty); }
  set { this.SetValue(CompanyNameProperty, value); }
}

private void btnChange_Click(object sender, RoutedEventArgs e) {
  this.CompanyName = "This is new company from code beind";
}

Regards,


Source: (StackOverflow)

Why does "local" sweep the return code of a command?

I was experiencing a problem with exit codes in a Bash script (GNU bash 4.1.7) till I found its origin in this surprising (at least for me) behavior of local. Let me show a simplified example:

$ fun() { local x=$(false); echo "exit code: $?"; }
$ fun
exit code: 0

Compare it with:

$ fun2() { x=$(false); echo "exit code: $?"; }
$ fun2
exit code: 1

The last one works as I'd expect. I've read the manual page, the TLDP tutorial, but I found no references to this specific situation. Can anyone explain this behavior?


Source: (StackOverflow)