Skip to content

Instantly share code, notes, and snippets.

View sumitasok's full-sized avatar

Sumit. M. Asok sumitasok

View GitHub Profile
@sumitasok
sumitasok / design-for-crud-method-interface.go
Created May 27, 2016 10:37
Design for Crud method interface for apis.V2
type Controler struct{
}
func c Controller Config() apis.Config{} {}
func c Controller BeforeFilters() []actions {
if Methdo == "POST" {
retuen []actions{}
} esles is "PUT"
@sumitasok
sumitasok / flatten_list.rb
Created May 17, 2016 11:09
Flatten an arbitrarily nested array
def flatten_array(array)
flattened_array = []
array.each do |element|
if element.kind_of?(Array)
flatten_array(element).each do |sub_element|
flattened_array << sub_element
end
else
flattened_array << element
end
why you need break and contibue
for() {
if {
break
} else {
body;
}
}
// emphasise on what is what by method
softDelete(obj){
update bson.status = "deleted"
}
hardDelete(obj) {
mongo.Delete(obj.ID)
}
People - soft deleted
_id, preview_token
permalink, preview_token
type publicQueryGen bson.M
type manageQueryGen bson.M
func (qG publicQueryGen) Get(config) ([]Events, error) {
var e []Ebvents
err := return db(config.DB).C(config.C).Find(qG).All(&e)
return e, err
@sumitasok
sumitasok / main.go
Created April 20, 2016 06:54
Interface implementation for Golang, to ensure never ever unauthorised data is wrongly pulled.
// model
fund getPublicEvents(status, publish_status string, isPrivate bool)
EventMeta{}
Events {
GetALL() []Events
}
ManageEvent struct{

This post deals with using rethinkdb with python repl

Do your installations

Note: in every python example, I have intended it wrongly for easy reading. Please make it into a single line, before pasting in the Repl. Try typing.

Get the Conn

[]

@sumitasok
sumitasok / command.py
Last active August 29, 2015 14:24
rethinkdb reports dummy data
conn = r.connect(host="localhost", port=28015, db="arkinventory", auth_key="", timeout=20)
r.table("reportsdata").
concat_map(lambda attendees: [attendees['attendees']]).
concat_map(lambda attendees: attendees['attendees']).sample(4).run(conn)
r.table("reportsdata").
concat_map(lambda attendees: attendees['attendees']).
filter({'ticketId': "ticket-id-4321"}).sample(3).run(conn)
@sumitasok
sumitasok / file_replace.sh
Last active August 29, 2015 14:19
Shell Script collection
# add a string in a field to line number (15)
perl -pi -e 'if($.==14){s/\n/\n\/\/ ABC\n/g}if(eof){$.=0}' Makefile.txt
# replace regex with environment variable
perl -pi -e 's/(([0-9]+.){3}([0-9]+))/'$dIPmysql'/g' t.sh
@sumitasok
sumitasok / conn.go
Last active August 29, 2015 14:18
Mongo Mgo Cheat Sheet
func mgoSession() *mgo.Session {
uri := "127.0.0.1"
if uri == "" {
fmt.Println("no connection string provided")
os.Exit(1)
}
sess, err := mgo.Dial(uri)
if err != nil {
fmt.Printf("Can't connect to mongo, go error %v\n", err)