Django: Quick snippet to get user from session ID

This is pretty much a drop-and-go snippet.

def get_user_from_session(session_key):
from django.contrib.sessions.models import Session
from django.contrib.auth.models import User

session = Session.objects.get(session_key = session_key)
uid = session.get_decoded().get('_auth_user_id')
return User.objects.get(pk = uid)

user = get_user_from_session('6117e4e8882448931b3de1f2440243ff')
print user.username, user.get_full_name(), user.email

That's it!

Lu6DW
Now, back to being productive...

Source

Twitter: Change number of results from twitter search API

The twitter search API is pretty flexible, but one of the things I wanted was to increase the number of results fetched.

By default, it returns about 20. The API is accessed through:

http://search.twitter.com/search.json?q=query&rpp=itemsperpage&page=pagenumber

Could have just been me, but I couldn't find the "results per page" (rpp) argument anywhere in the docs.

You can continue through the pages by feeding it new "page" numbers.

1311359396_129175753884361380
Now go nuts, knock yourself out!

Source

Word/Excel: How to add strike-through (or any other command) to toolbar

This is such an easy task but I've never thought of doing it before! Why!?

image
Current toolbar, without strike-through.

  • Right click the toolbar and click "Customise"
  • Click on "Commands" tab then the group of commands you want.
  • In this case, I want "Formatting".

image

  • Find "Strike-through" in the list and drag it to the position in a toolbar you want
  • Laugh at how easy it is and proceed with striking things out!

deadpool-iDbAEnCEnthry
Deadpool dancing with Castle Crashers? Sure why not!

Sources

Facebook: Remove Recent Places from Timeline

Fuck you Facebook.

Seriously, location awareness disabled on my phone. Not using your information siphoning app and you STILL extract location data from photo EXIF and ISP information.

image
THAT shit!

image
And this shit in the red circle!

Anyway, to remove the recent locations widget from your timeline, do the following:

  • Go to your profile (by clicking on your name in the top right)
  • Just under your cover picture, there are a few squares such as "Friends" and "Photos"
  • Beside it should be a little triangle pointing down (blue circle). Click it.
  • A pencil should appear on the Maps favourites
  • Remove that shit from favourites.
  • Click the triangle again.

Now, don't be freaked out if you still see it in your profile. It'll still appear to YOU, but not anyone else.

To try it out:

  • Click on the cog next to "Activity log" (blue circle)
  • Select "View as"
  • Type in your friend's name and select them
  • You should not see the maps widget in the favourites nor further down in your timeline.

Now you can continue using Facebook without worrying about people scoping out your locations, GANGNAM STYLE!

tumblr_m7759dfBXa1qitqsuo6_r1_250
This cowboy thrusting scene has gotta be one of the best!

Sources

Senate Petition Regarding National Security Inquiry

If you're sick of the Government trying to corrode our online rights, sign this petition backed by the Australian Pirate Party!

I do no wrong, but I'm annoyed at being treated like a criminal.

Being thrown in prison because I don't want to give my encryption keys to my online passwords? Fuck off!

http://pirateparty.org.au/natsecinquiry-petition/

Say something about it now or forever lose your rights.

yyuiU
FIGHT BACK, GET MAD!

Blogger.com: Disable country domain redirects

I'm getting annoyed at my web traffic stats being all messed up because the URLs aren't being counted properly.

Popular Pages - Twigs Tech Tips

People browsing from different part of the world are being redirected to their government friendly top level domains (TLD's) and it's just annoying.

This is meant to be the internet, a place where information roams free from the slow red tape of bureaucracy.

Thankfully, there's a quick fix for this and it doesn't involve any unnecessary pain.

2843_0c8f
  • Firstly, log in to your blogger.com admin.
  • Secondly, open up the dashboard for your blog.
  • Click "Template"
  • Click "Edit HTML"
  • Click "Proceed"
  • Select "Expand Widget Templates" at the top.
  • Using your browser, search for </head>
  • Just before that, paste this in:
<script type="text/javascript">
function check_redirect(your_domain) {
if (window.location.host.split('.').pop() != your_domain.split('.').pop()) {
var new_url = window.location.href;
new_url = new_url.replace(window.location.protocol + "//" + window.location.hostname, window.location.protocol + "//" + your_domain + "/ncr");
window.location.href = new_url;
}
}

check_redirect("twigstechtips.blogspot.com.au");
</script>
  • Change the 2nd last line to whatever you want your domain to be. In this case, I want to enforce it so everyone visits the .au one.
  • Click save.
  • Test it out!

Source

Originally I found the information from here, but from inspection it doesn't seem to cover all the domains I have been seeing in the stats such as .co.uk.

I've rewritten it a little so it does the domain detection and replacement better.

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog