parseInt is a javascript function that can't be relied to return NaN in some strings that are not numbers
parseInt('12lol')
returns 12
parseInt('lol12')
returns Nan
A more reliable function to do this is Number()
Number('12lol')
returns Nan
Number('293.2')
returns 293.2
parseFloat has the same defect, don't rely on those.
lunes, 21 de mayo de 2012
miércoles, 7 de marzo de 2012
Forma de dineromail comentada
Forma de dineromail comentada:
Me topé con el problema de implementar una forma de dineromail y la escasa documentación no ayudaba asi que espero esto le sirva a mas personas.
Si necesitas enviar a dineromail a un usuario y quieres saber que campos necesitas pasar en el POST esta forma te será útil, no es una referencia completa, para eso necesitas ir a por el manual que dineromail ofrece
jueves, 1 de marzo de 2012
My django snippets
In this post i'd like to share info on snippets i've shared on the very nice django-snippets.org.
My list
My list
-
Encrypted paypal buttons :
Use the code here if you want to encrypt your paypal buttons to pass sensitive information, like the receipt_id if you use it to validate a payment in your end. -
Redirect to no slash:
In django there is this setting APPEND_SLASH that does the oposite to my snippet, adds a slash and redirects there, but i wanted the oposite, i think urls look better like that.
So far the only problem i've had with this approach is Facebook likes code. When you insert a facebook like iframe it checks the url you send it and follows redirections, so for urls with these kinds of codes you should disable the redirection. - Save image in field :I ended up not using this code, and instead i went with the more generic get_img_obj because i wanted a one function fits all to get images from external source inside my imagefields.
-
Send templated email with text | html | optional files
Use this function to send email with html that automatically degrades to text if the client does not support html.
- Generate a dineromail form in python
This code is pretty generic and its just to show some idiosyncrasies of the dineromail API.
jueves, 23 de febrero de 2012
Why the rotate does not work on chrome
I think i need to rebrand this blog as a general web development blog.
The case today is about the css property to rotate an element, for good measure this is the code for all browsers to rotate elements
If chrome refuses to work using this line
And thats it. have fun!
UPDATE:
The sass mixing to rotate an element
The case today is about the css property to rotate an element, for good measure this is the code for all browsers to rotate elements
#yourelement {
-moz-transform: rotate(180deg)
-o-transform: rotate(180deg)
-webkit-transform: rotate(180deg)
filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=#{cos(180deg)}, M12=-#{sin(180deg)}, M21=#{sin(180deg)}, M22=#{cos(180deg)})
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=#{cos(180deg)}, M12=-#{sin(180deg)}, M21=#{sin(180deg)}, M22=#{cos(180deg)})"
zoom: 1
}
So thats the code to rotate an element 180 degrees, i used it to rotate a bang ! sing because in spanish you need the rotated version to start a sentence.If chrome refuses to work using this line
-webkit-transform: rotate(10deg);You are probably tring to target an inline element, this could be a inline element by default so i solved my problem enveloping what i wanted to rotate in a div, and setting its display property to inline.
And thats it. have fun!
UPDATE:
The sass mixing to rotate an element
@mixin rotate($degrees)
-moz-transform: rotate($degrees)
-o-transform: rotate($degrees)
-webkit-transform: rotate($degrees)
filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=#{cos($degrees)}, M12=-#{sin($degrees)}, M21=#{sin($degrees)}, M22=#{cos($degrees)})
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=#{cos($degrees)}, M12=-#{sin($degrees)}, M21=#{sin($degrees)}, M22=#{cos($degrees)})"
zoom: 1
And you would use it like this@include rotate(90deg)Dont forget to import them if you have the mixins in another file!
Etiquetas:
browsers rotate,
css rotate,
rotate element
miércoles, 22 de febrero de 2012
How to submit a form with a click on an arbitrary element.
This is real live code for Bandtastic.me
What i wanted to accomplish was a clickable div with a text box in it that submits a form, this is to bypass the limitations of a regular form that needs a submit button.
I'm posting this because it was a real pain to get this functionallity and i hope somebody can save itself the trouble.
So you have a div with a textbox in it, roughly this

And you want to be able to submit the contents of the textbox as a regular html form.
You can style your form as a regular div, like i did in the screenshot.
Now the magic would rely on jquery so remember to include it in your html and then would be this
First we target all the elements on our form using the *, so when any or subelement can be used to submit the form
We submit the form with another handy jquery method.
Thats it, if you have any questions or remarks leave a comment.
What i wanted to accomplish was a clickable div with a text box in it that submits a form, this is to bypass the limitations of a regular form that needs a submit button.
I'm posting this because it was a real pain to get this functionallity and i hope somebody can save itself the trouble.
So you have a div with a textbox in it, roughly this

And you want to be able to submit the contents of the textbox as a regular html form.
<form method='GET' action='/post' id='myform'> <input type='text' id='mytextbox' value='100' /> </form>Something like that, so no button anywhere to be found.
You can style your form as a regular div, like i did in the screenshot.
Now the magic would rely on jquery so remember to include it in your html and then would be this
$(function(){
$('.custom_contribution *').click(function(event){
event.stopImmediatePropagation()
if(! $(event.currentTarget).is('input#custom_ammount')){
$('.custom_contribution').submit();
}
});
})
Lets analyze thisFirst we target all the elements on our form using the *, so when any or subelement can be used to submit the form
$('.custom_contribution *').click(function(event)(
Then we stop the propagation of the event so if there are elements underneath that jquery also considers clicked we only get oneevent.stopImmediatePropagation()Then we check with if the clicked element is not our textbox
if(! $(e.currentTarget).is('input#custom_ammount')){
We do this converting the dom element that e.currenTarget returns to a jquery object surrounding it with $()we do this so we can the use
is()method that will return true if the element is our textbox, and because we have a boolean negation ! the next line of code only will run if we clicked anything but the textbox.
We submit the form with another handy jquery method.
$('.custom_contribution').submit();
This allow us to have a huge clickable button while mantaining the form functionality, because if you type something in the textbox and then hit enter, it will also submit it.Thats it, if you have any questions or remarks leave a comment.
Etiquetas:
capture click,
click multiple elements.,
form,
jquery,
submit without button
jueves, 9 de febrero de 2012
Facebook chat is not loading
Troubleshotting Facebook code
Any Facebook code got in https://developers.facebook.com/docs/plugins/ such as:
Any Facebook code got in https://developers.facebook.com/docs/plugins/ such as:
- Like Button
- Send Button
- Subscribe Button
- Comments
- Activity Feed
- Recommendations
- Like Box
- Login Button
- Registration
- Facepile
- Live Stream
- First go to the facebook debugger and input the problematic url, sometimes just doing it, fixes problems such as wrong meta data or wrong likes numbers.
- Is the required Javascript sdk in the header of your site? it doesnt work if you move it to the bottom
- Is the code copy pasted right, some template systems can mess your code, so make sure yours get the appropriate VERBATIM, :plain or whatever tag your templating system uses to pass textual content.
- Are your running the code on the same url the code is configured in.
- Is the code inside a div or an element with an id, this can be tricky to spot, but some Facebook code requires some css selecting that can be messed up if you put it inside an html element with an id.
- Any other common mistakes, please post them in the comments.
Fixing facebook on firefox
If you use Firefox and the new Facebook photo display mode the photos are out of place, and by out of place i mean they are wrongly placed.
Go get the stylish addon and add this rule for facebook:
Go get the stylish addon and add this rule for facebook:
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("facebook.com") {
.stage img{
position:relative;
top: -100%;
}
}
Suscribirse a:
Entradas (Atom)