Kaviraj       Archive       Tags

Go-gorm: JOINS make life easier!

I have been using go-lang and gorm to build web apps for a while. Though gorm provids very good documentation, I think it lacks some real-time examples. Here is what I have learned how to use gorm for advanced queries. Most importantly to get data from multiple tables that are not directly related.

Let me try explaining the concepts with three use cases.

Consider following models

type Launguage struct {
	ID uint `gorm:"primary_key"`
	Name string
}
	
type Movie struct {
	ID uint `gorm:"primary_key"`
	Title string
	LaunguageID uint
	Launguage Launguage
}

type Artist struct {
	ID uint `gorm:"primary_key"`
	Name string
	Movies []Movie `gorm:"many2many:artist_movies"`
}

Read More

#ORM #go #golang #sql

Django: Internals series - Gotchas

Hi Everyone. Welcome to Django internal series. Goal of this entire series is to share my experience on understanding the internals of django.

In part 1 of this series we try to understand why its important to understand django internals.

I started using django about an year ago. It’s a part of our company’s technology stack. We love building apps with Django(of course who wouldn’t?). During early stage of using django, I really suck at debugging as I felt django is doing lot of magic under the hood. Few basic questions started bothering me.

  1. I am declaring all fields in model as class variables. How come I am able to access those as instance variables on any of those model instances?
  2. What is happening when I access any field of a model instance. For e.g take a look at simple_django_model.py snippet below. There we have single field called email of type models.EmailField(). Now if try to get user.email it should technically return models.EmailField instance right?, but django does some magic and return the exact email address as string [email protected]
  3. How does “class Meta” inside any model affects the model behaviour?
  4. What does really ‘app’ mean to django?(HINT: Every directory with __init__.py is not an app)
  5. How django creates actual model instance from db tables?

And much more basic questions..

Read More

#django #python

Python: Generating pdf containing emojis using reportlab

Understanding Emoji

Emojis 😃 🎉 👍 💕 have become so popular. Anyone who used Whatsapp or Instagram knows how cool emojis are 😎. And they are everywhere now. Emoji originated in Japan. The word “emoji” means “Picture(e) letter(moji)” in Japanese.

Technically, emojis are subset of Unicode character set. In short, Unicode is the collection of every writable symbol available on the planet. That being said, unicode includes symbols from every language that exist.

There are different types of encoding used to interpret different sets of unicode. Most popular is “UTF-8” encoding. To understand how unicode are interpreted, stored and retrieved here is a great article The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Every emoji is a single unicode character that can be upto 4 bytes long depending on type of encoding used. Yes, every character is just one byte is no longer true.

Read More

#emoji #python #reportlab

Review: Emacs Lisp Intro Manual

Once you start using emacs for most of your editing/coding tasks, then that will make you serious about using it productively

From then on, you can no longer use Emacs without customizing it. Yea, of course there are tons of elisp code snippet out there to customize it just by copy pasting without understanding what it does or how it works.

But that no longer works on the longer run. At some point of time you have get started on learning Emacs lisp.

Same thing happened to me few weeks back. I got tired of customizing emacs just by including some piece of elisp code from somewhere on the internet into my .emacs file without even understanding what the code does.

So at the end,

  • My .emacs file got messy without organizing.
  • Its very frustating to debug if something goes wrong.
  • I started to get afraid of parenthesis 😧

Just then, I figured it out I just need to get started on learning Emacs lisp.

Read More

#elisp #emacs