Skip to content

Instantly share code, notes, and snippets.

View psanzay's full-sized avatar

Sanjay Pandey psanzay

View GitHub Profile
@psanzay
psanzay / deserialize.python
Created March 30, 2020 15:32
reading data from file
import json
# open file
f = open("data.json")
# read data
line = f.readline()
#deserialize
data = json.loads(line)
import json
# open file for storing data
f = open("data.json", w)
# create object
person = {"name": "test", ...}
# store in file
f.write(json.dumps(person))
@psanzay
psanzay / deserialize.go
Created March 30, 2020 14:58
deserialize data
in, err := ioutil.ReadFile("persons")
if err != nil {
log.Fatalln("Error reading file:", err)
}
person := &pb.Person{}
if err := proto.Unmarshal(in, person); err != nil {
log.Fatalln("Failed to parse person list:", err)
}
@psanzay
psanzay / serializing.go
Created March 30, 2020 14:55
serializing protocol buffer
person := &pb.Person{}
person.Name = "test"
.... other fields ...
out, err := proto.Marshal(person)
// writing to file
if err != nil {
log.Fatalln("Failed to encode person:", err)
}
if err := ioutil.WriteFile("phones", out, 0644); err != nil {
log.Fatalln("Failed to write person:", err)
@psanzay
psanzay / person.pb.go
Created March 30, 2020 14:44
protocol buffer file for go
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: message.proto
package message
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
@psanzay
psanzay / class.proto
Last active March 30, 2020 14:41
protocol buffer definition
syntax = "proto3";
message Person {
string name = 1;
string email = 2;
string city = 3;
string state = 4;
string country = 5;
int32 age = 6;
string phone = 7;
@psanzay
psanzay / gopath.txt
Last active August 6, 2017 04:24 — forked from molivier/gist:271bba5d67de1583a8e3
Set $GOPATH on Mac OSX : bash_profile
# Edit ~/.bash_profile
# GOPATH is used to specify directories outside of $GOROOT that contain the source for Go projects and their binaries.
export GOPATH=/Users/username/go
export PATH=$GOPATH/bin:$PATH
# Reload profile : source ~/.bash_profile
@psanzay
psanzay / adt.sh
Created March 6, 2017 13:07
Installing angular2 dependencies and types
npm install --save-dev @types/node @types/core-js webpack@latest webpack-dev-server@latest webpack-merge angular2-template-loader awesome-typescript-loader angular2-router-loader del-cli html-loader html-webpack-plugin lite-server raw-loader typescript
@psanzay
psanzay / gunicorn_start.bash
Created January 10, 2016 07:21 — forked from postrational/gunicorn_start.bash
Example of how to set up Django on Nginx with Gunicorn and supervisordhttp://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
#!/bin/bash
NAME="hello_app" # Name of the application
DJANGODIR=/webapps/hello_django/hello # Django project directory
SOCKFILE=/webapps/hello_django/run/gunicorn.sock # we will communicte using this unix socket
USER=hello # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=hello.settings # which settings file should Django use
DJANGO_WSGI_MODULE=hello.wsgi # WSGI module name
@psanzay
psanzay / .gitconfig
Last active August 29, 2015 14:14 — forked from orj/.gitconfig
[merge]
keepBackup = false
tool = custom
[mergetool "custom"]
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "$PWD/$BASE" "$PWD/$REMOTE" "$PWD/$LOCAL" "$PWD/$MERGED"
keepTemporaries = false
trustExitCode = false
keepBackup = false