Sunday, 1 September 2013

Cannot attach file using Proxy

Cannot attach file using Proxy

I'm develop my own csharp proxy (using Socket), everything going fine
except for two things: 1. even on HTTP WebMail user cannot doing file
attachment (other email function is ok, including download attachment) 2.
It cannot handle HTTPS (443)
The 1st problem I'm very concern with, the 2nd problem if there is
solution is also great, do you guys have suggestion what it's all about?

Authenticated call to MtGox WebSocket API in Python 3

Authenticated call to MtGox WebSocket API in Python 3

I'm trying to authenticate with the MtGox.com WebSocket API and after a
long while managed to complete the required "call" attribute of the JSON
data. However, I realized that I was using Python 2 to run my codesample
and the application the API is finally going to be implemented in is
written in Python 3. When I tried to make it work in Python 3 I ran into a
couple of problems I was unable to resolve despite several long attempts.
I also tried 2to3, but seems it doesn't have builtin fixers for these
kinds of problems.
The API specification for authenticated API calls can be found here:
https://en.bitcoin.it/wiki/MtGox/API/Streaming#Authenticated_commands
Here is the working Python 2 script I used for generating the JSON call
which I then ran through a WebSocket console extension I found for Chrome.
import hashlib
import time
import hmac
import json
import base64
import binascii
apikey = ""
apisecret = ""
def _nonce():
"""produce a unique nonce that is guaranteed to be ever increasing"""
microtime = int(time.time() * 1E6)
return microtime
def _reqid(nonce):
return hashlib.md5(str(nonce)).hexdigest()
def send_signed_call(api_endpoint, params):
nonce = _nonce()
reqid = _reqid(nonce)
call = json.dumps({
"id" : reqid,
"nonce" : nonce,
"call" : api_endpoint,
"params" : params,
})
sign = hmac.new(base64.b64decode(apisecret), call,
hashlib.sha512).digest()
signedcall = apikey.replace("-", "").decode("hex") + sign + call
return json.dumps({
"op" : "call",
"call" : base64.b64encode(signedcall),
"id" : reqid,
"context" : "mtgox.com"
})
msg = send_signed_call("private/info", {})
print(msg)
Some of the errors I ran into related to the no longer existing
String.decode("hex"), I've had a few others but unfortunately I haven't
kept track of all of them as I tried a great deal of different approaches.
I also looked at codesamples of the same functionality in other languages
but couldn't find any clue relating to the Python 3 problem. A lot seems
to be having to do with changes made to bytes and strings encoding and
decoding in Python 3.
Thanks a lot in advance!

how to update a value from 'controller', in a 'directive'?

how to update a value from 'controller', in a 'directive'?

I write a 'dialog' directive for testing,but I don't know how to update
the value from controller in a directive
app.controller('testController',function($scope){
$scope.testValue = 'testing';
});
app.directive('testDirectvie',function(){
return function(scope,element,attr){
// this func will open the modal window,
// so how can I can the testValue from controller?Thx all
};
});

Saturday, 31 August 2013

How to change a character of an string into a different character?

How to change a character of an string into a different character?

I want to convert the space in a string into another character.
Ex:
var country = "United States"
I want the space to be "-" so:
var country = "Unites-States"
This is what I tried:
var country ="United States";
var countryArray = country.split(" ");
var newCountry = function(){
for(i=0;i<countryArray.length;i++){
if(countryArray[i]===","){
return countryArray[i]="-";}
}

How to fix scrolling issues with liquid layout image 100% width and height?

How to fix scrolling issues with liquid layout image 100% width and height?

I am using a liquid layout on my site. The background is a an image (
slideshow ) and it works how I want. The photo stretches and resizes with
the size of the browser.
However, I just noticed that when I move my browser window as thin or
narrow as it goes, the image is still there but when I scroll to the right
the image cuts off into the background. But full size works fine.
basically I want it to be 100% width and height at all times and never
scroll horizontally or ever exposing the body.
Please let me know what else you need to know to help. Here is the html
and css. thanks
#revolver {
background-color:#ccc;
width:100%;
min-height:100%;
z-index:10001;
}
.revolver-slide {
width:100%;
min-height:100%;
background-position:center center;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
}
.revolver-slide img {
width:100%;
min-height:100%;
}
.page-section {
width:100%;
height:100%;
margin:0px auto 0px auto;
}
html,body {
height:100%;
}
<div class="page-section clear">
<!-- 100% width -->
<div id="revolver">
<div class="revolver-slide" style="background-image:url('<?php
bloginfo('template_directory');?>/img/slides/slide-6.jpg');"></div>
<div class="revolver-slide" style="background-image:url('<?php
bloginfo('template_directory');?>/img/slides/slide-2.jpg');"></div>
<div class="revolver-slide" style="background-image:url('<?php
bloginfo('template_directory');?>/img/slides/slide-8.jpg');"></div>
<div class="revolver-slide" style="background-image:url('<?php
bloginfo('template_directory');?>/img/slides/slide-11.jpg');"></div>
<div class="revolver-slide" style="background-image:url('<?php
bloginfo('template_directory');?>/img/slides/slide-7.jpg');"></div>
<div class="revolver-slide" style="background-image:url('<?php
bloginfo('template_directory');?>/img/slides/slide-4.jpg');"></div>
<div class="revolver-slide" style="background-image:url('<?php
bloginfo('template_directory');?>/img/slides/slide-9.jpg');"></div>
</div>
</div>

Add more constraints to my controllers list method

Add more constraints to my controllers list method

At the moment my controllers list method for the domain object Product is:
def list(Integer max) {
params.max = Math.min(max ?: 10, 100)
[productInstanceList: Product.list(params), productInstanceTotal:
Product.count()]
}
I wish to add more constrains to this. More specifically, I want to get
the logged in user. This has a M:1 relationship to a domain entity called
Manager. Manager has a M:M relationship to domain entity Company. Company
has a 1:M relationship to Product. So I want to only return products that
are from the appropriate company.
I start by doing:
def list(Integer max) {
// 1. Get logged in user.
def user = springSecurityService.currentUser;
// 2. Get corresponding manager.
Manager mgr = user.getManager();
// 3. Get corresponding companies
companies = mgr.getCompanies();
// 4. Get products for all companies - not sure smart way to get this.
// 5. Need to add the products to the query
...
}
As can be seen I get stuck at steps 4, 5. Using raw SQL I would just to a
join to represent to all the User's Manager's Companies' Products and then
put this in as a where predicate and hit the product table.
But I want a grails / groovy solution. I also need to keep the params in
the query as this controller can also have params injected which are pass
into the query,
Any tips?

Meaning of Log f0 delta

Meaning of Log f0 delta

I am just walking through a really long section of code that I need to
rework for a company. I have to re-write it in a different language.
This code deals with calculating "log f0 delta". This has something to do
with audio and a pitch curve.
My question would be: Does anybody know from just hearing this topic what
is done there? The code is REALLY huge, and I would really like to
understand what exactely is calculated there before I re-write it. That
would make it easier for me.
Thank you very much for the help!