lundi 31 août 2015

asp call to java script removes brackets

I am new to asp and vbscript and attempting to pass a database critera list to javascript. The criteria will be used in sql statements in clause, if that is what it is called. The problem is the parethesis are removed!

The criterias for the in clause look like

  • "('Not Defined')"
  • "('A Condition')"
  • "('B Condition')"
  • "('C Condition', 'D Condition')"
  • "('E Condition', 'F Condition', 'G Condition')"
  • "('H Condition', 'I Condition', 'J Condition', 'K Condition')"

The javascipt take to parameters for row and column and searches a database and returns a list of table entries dependent on those conditions or set of conditions.

I've been working with the following:

Response.Write "<td WIDTH='6%'  VALIGN='TOP' ALIGN='CENTER' bgcolor = " & ObjDic(elem).clrPreExisting & ">" & vbCRLF
Response.Write "<a href = ""javascript:alert("objDic(elem).critRow")""><font size='2' face='Arial' color='#000000'>" & ObjDic(elem).Get_PreExistingVal(RunningTotal.PreExisting) & "</font></a>" &vbCRLF
Response.Write "</td>" & vbCRLF

the value of objDic(elem).critRow from the immediate window shows

objDic(elem).critRow "('Not Defined')" But thie Java alert shows Not Defined.



via Chebli Mohamed

Converting curl call to Java

I login to a server (php page) using the code below:

$curl -b cookies --output 'result' \
    --data 'user=me@myself.com' \
    --data 'password=donttellanyone' \
    http://ift.tt/1JxDJA3

After executing this command in terminal, a file named result will be created and inside it is just a html page that says login success.

But I now want to do the same thing using a Java console application...but I havent got any success yet. Executing this Java code results in error. I guess it is because I am not giving username and password in a correct way.

This is my code:

URL url = new URL("http://ift.tt/1jbM0iA");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestProperty("Cookie",  "username=" + email + "; password=" + pwd);
conn.connect();

So the question is how to convert the above curl command to Java code?



via Chebli Mohamed

add class on html tag

I am try to apply a class on HTML tag, if the tag exists.

i try this code...

<!DOCTYPE html>
<html xmlns="http://ift.tt/lH0Osb">
<head>
    <title>index</title>

    <style>
        .black
        {
            background:#000;
            color:white;
        }

    </style>
    <script type="text/javascript">
        $(window).load(function () {
            $('textarea').addClass('black');
        });
    </script>
</head>
<body>

    <div>


        <textarea>content</textarea>


    </div>

    <script src="jquery.js"></script>

</body>
</html>

What i want: If the html body contain textarea tag the the .black class will apply on it automaticly.



via Chebli Mohamed

PortAudio: Playback lag at default frames-per-buffer

I'm trying to play audio in Go, asynchronously, using PortAudio. As far as I'm aware PortAudio handles its own threading, so I don't need to use any of Go's build-in concurrency stuff. I'm using libsndfile to load the file (also Go bindings). Here is my code:

type Track struct {
    stream   *portaudio.Stream
    playhead int
    buffer   []int32
}

func LoadTrackFilesize(filename string, loop bool, bytes int) *Track {
    // Load file
    var info sndfile.Info
    soundFile, err := sndfile.Open(filename, sndfile.Read, &info)
    if err != nil {
        fmt.Printf("Could not open file: %s\n", filename)
        panic(err)
    }
    buffer := make([]int32, bytes)
    numRead, err := soundFile.ReadItems(buffer)
    if err != nil {
        fmt.Printf("Error reading from file: %s\n", filename)
        panic(err)
    }
    defer soundFile.Close()

    // Create track
    track := Track{
        buffer: buffer[:numRead],
    }

    // Create stream
    stream, err := portaudio.OpenDefaultStream(
        0, 2, float64(44100), portaudio.FramesPerBufferUnspecified, track.playCallback,
    )
    if err != nil {
        fmt.Printf("Couldn't get stream for file: %s\n", filename)
    }
    track.stream = stream

    return &track
}

func (t *Track) playCallback(out []int32) {
    for i := range out {
        out[i] = t.buffer[(t.playhead+i)%len(t.buffer)]
    }
    t.playhead += len(out) % len(t.buffer)
}

func (t *Track) Play() {
    t.stream.Start()
}

Using these functions, after initialising PortAudio and all the rest, plays the audio track I supply - just. It's very laggy, and slows down the rest of my application (a game loop).

However, if I change the frames per buffer value from FramesPerBufferUnspecified to something high, say, 1024, the audio plays fine and doesn't interfere with the rest of my application.

Why is this? The PortAudio documentation suggests that using the unspecified value will 'choose a value for optimum latency', but I'm definitely not seeing that.

Additionally, when playing with this very high value, I notice some tiny artefacts - little 'popping' noises - in the audio.

Is there something wrong with my callback function, or anything else, that could be causing one or both of these problems?

Thanks.



via Chebli Mohamed

DockerHub Private Repo Login. More secure way?

I've seen articles such as this one about pulling from private repos and the "best" way to do it. What I understand is, if I want to automate any infrastructure to pull my docker images from dockerhub I need to:

  • Have a user I can login with.
  • Save the users creds in some application that will spin up my infrastructure (be it EC2 User data, a config file for ansible, or ENV variables in some API).
  • When the machine spins up it uses this user's credentials to login and place a token on the machine. All is well.

I'm wondering if there is any functionality to use application keys / tokens instead of needing to tie this to a user. It seems like it would be more secure/convenient if I could manage application keys to do have access to my user/organization's DockerHub account. Then I could yank the keys or change my password and not worry about the sky falling.

Is something like this available, coming, or is there a solution I haven't come across yet?

Thanks!



via Chebli Mohamed

Android Studio. Can i use startLockTask() on app X from app Y knowing the packageName of X?

The titles says it all. I want to start the LockTask introduced in lollipop on an app from another app. Can i do such thing ? Ty.



via Chebli Mohamed

How to add placeholder text to yii inputfield?

iam using clevertech an extension for YII, dose anybody know how i can add my own custom placeholder text inside the input. Below is an example of the input filed:

<?php echo $form->textFieldGroup(
            $model,
            'textField',
            array(
                'wrapperHtmlOptions' => array(
                    'class' => 'col-sm-5',
                ),
                'hint' => 'In addition to freeform text, any HTML5 text-based input appears like so.'
            )
        ); ?>



via Chebli Mohamed