Skip to content

Instantly share code, notes, and snippets.

View kavirajk's full-sized avatar
😎
Talk distributed systems to me!!

Kaviraj Kanagaraj kavirajk

😎
Talk distributed systems to me!!
View GitHub Profile
@kavirajk
kavirajk / simple_django_model.py
Last active December 6, 2015 19:15
Models and python object difference
from django.db import models
class User(models.Model):
email = models.EmailField()
obj = User(email='[email protected]')
print(User.email)
# output: AttributeError: type object 'User' has no attribute 'email'
print(obj.email)
@kavirajk
kavirajk / 0_reuse_code.js
Created November 2, 2015 03:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kavirajk
kavirajk / python_getter_setter.py
Last active December 6, 2015 18:13
Simple python getter and setter example
class EmailField(object):
def __init__(self, email=None):
self.email = email
def __set__(self, email):
self.email = email
def __get__(self, email):
return self.email
@kavirajk
kavirajk / gorm_joins.go
Created April 17, 2016 18:55
Understanding Joins in gorm
package main
import (
"fmt"
"log"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
)
@kavirajk
kavirajk / emails.go
Last active July 15, 2016 14:23
Send Email (cannot be mocked)
package email
import (
"bytes"
"html/template"
"os"
"gopkg.in/gomail.v2"
)
@kavirajk
kavirajk / emails.go
Last active July 15, 2016 14:13
Send Email (can be mocked)
package email
import (
"bytes"
"html/template"
"os"
"gopkg.in/gomail.v2"
)
@kavirajk
kavirajk / emails_test.go
Last active July 15, 2016 10:10
Send Email unit tests
package email
import (
"bytes"
"html/template"
"reflect"
"testing"
)
type FakeEmailSender struct {
@kavirajk
kavirajk / config.go
Created July 15, 2016 10:15
Load config from environment variables
package envron
import (
"log"
"os"
)
func MustEnv(key string) (value string) {
if value = os.Getenv(key); value == "" {
log.Fatalf("ENV %q is not set.", key)
@kavirajk
kavirajk / config_test.go
Created July 15, 2016 10:16
Test GetEnv function
package envron
import (
"os"
"os/exec"
"testing"
)
func TestMustEnv(t *testing.T) {
// If env variable "TEST" is not set then fatal it
@kavirajk
kavirajk / reset_password.go
Last active July 15, 2016 11:22
Resets User's password stored in db
// WARNING: This command is supposed to be used only by admin
package main
import (
"flag"
"fmt"
"log"
"code.launchyard.com/root/myserver/config"