blog.mattcrampton.com

  • Archive
  • RSS

Force VIM to stop overwriting your default buffer when pasting

I use VIM all the time for development, one thing that always bugs me is when I yank a chunk of code into my default buffer, and then paste if over something else, VIM will take whatever was pasted over and overwrite my default buffer with it.  So the next time I try to paste, it will paste the previously pasted over text instead of the original stuff I yanked.  Stick the following line into your .vimrc file to fix this…

xnoremap  P v:register=='"'?'pgvy':'p'

It remaps “P” to paste and then pull back into your default buffer the same stuff you pasted so it’s there to paste again.  Very handy for me.

  • 7 months ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Fixing “Viewport argument value” error in webkit’s console

I’ve been doing a lot of web development for mobile devices lately, and while I’ve been using chrome’s developer tools, I keep getting annoying error messages in the console like this…

Viewport argument value "1;" for key "initial-scale" was truncated to its numeric prefix. 

The culprit here is my viewport meta tag.  Mine looked like this… 

<meta name="viewport" content="width=device-width; height=device-height; initial-scale=1; maximum-scale=1; user-scalable=0;">

Which looks correct at first glance, I probably copy and pasted it from another website somewhere.  But if you examine webkit’s documentation, you’ll notice that the separators are supposed to be commas, not semi-colons.  I fixed the separators so my meta tag looks like this now…

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=0">

And problem solved, my console log is nice and quiet now.

  • 8 months ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Copying a directory in linux while preserving permissions

Continuing on with my attempts to blog code and command snippets that I’ve found useful, Here’s a trick if you need to copy a directory recursively, but retain all the permissions set on the first one.  I needed this to back up a web app tree that had custom permissions set through out that I didn’t want to mess up…

cp -r --preserve /source_dir /destin_dir
    • #linux
    • #permissions
    • #cp
    • #command line
    • #unix
  • 8 months ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Fixing position:fixed elements stuck in the middle of the page on iPhone Safari

We ran into an annoying bug over at Gigwalk while building a mobile webapp running inside Phonegap.  We have a toolbar at the top of all our pages which is set to position:fixed, but every once in a while it would get stuck in the middle of the page.  We tried several different proposed solutions, but this one worked for us.  Run the following function after the page loads and it will force Safari to re-orient it’s elements and puts the position:fixed toolbar back where it was supposed to go.

var fixPositionFixedElements = function(elem){
        elem = elem || document.documentElement;

        // force a reflow by increasing size 1px
        var width = elem.style.width,
            px = elem.offsetWidth+1;

        elem.style.width = px+'px';

        setTimeout(function(){
                // undo resize, unfortunately forces another reflow
                elem.style.width = width;
                elem = null;
        }, 0);
};
    • #bug
    • #css
    • #fixed
    • #ios
    • #phonegap
    • #position
    • #position:fixed
    • #safari
    • #toolbar
    • #javascript
    • #jquery
  • 8 months ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Iterating over a dict in a jinja template

At the time of this posting, iterating over dictionaries inside a Jinja template is poorly documented, and it’s something I end up doing alot. Here’s how you do it, nice and simple…

<dl>
      {% for key, value in _dict.iteritems() %}
            <dt>{{ key }}</dt>
            <dd>{{ value }}</dd>
      {% endfor %}
</dl>

Easy after you know. See the full API: http://jinja.pocoo.org/docs/api/

    • #jinga
    • #dict
    • #loop
    • #flask
    • #python
    • #template
  • 8 months ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

About

Avatar My personal blog. Expect randomness.

Me, Elsewhere

  • @mattccrampton on Twitter
  • Facebook Profile
  • mattcrampton on Flickr
  • Linkedin Profile
  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Pixel Union Powered by Tumblr