Skip to content

Instantly share code, notes, and snippets.

@Hasstrup
Hasstrup / main.go
Last active December 29, 2018 21:31
Index
package main
import "flag"
var (
cmd = flag.String("cmd", "", "list or add?")
address = flag.String("address", "", "mongodb address to connect to")
database = flag.String("db", "", "The name of the database to connect to")
collection = flag.String("collection", "", "The collection (in the db) to connect to")
key = flag.String("field", "", "The field you'd like to place an index on")
@Hasstrup
Hasstrup / main.go
Last active December 29, 2018 21:32
package main
import (
"context"
"flag"
"log"
"github.com/mongodb/mongo-go-driver/mongo"
)
var (
@Hasstrup
Hasstrup / main.go
Last active December 29, 2018 19:35
func PopulateIndex(database, collection string, client *mongo.Client) {
c := client.Database(database).Collection(collection)
opts := options.CreateIndexes().SetMaxTime(10 * time.Second)
index := yieldIndexModel()
c.Indexes().CreateOne(context.Background(), index, opts)
log.Println("Successfully create the index")
}
func yieldIndexModel() mongo.IndexModel {
keys := bsonx.Doc{{Key: *key, Value: bsonx.Int32(int32(*value))}}
package main
import (
"context"
"flag"
"fmt"
"log"
"time"
"github.com/mongodb/mongo-go-driver/bson"
AllCops:
Exclude:
- "vendor/**/*"
- "db/**/*"
- "bin/**/*"
- "config/**/*"
- "app/assets/**/*"
- "Rakefile"
- "spec/spec_helper.rb"
- "spec/rails_helper.rb"
// assuming something we had a collection called movies and movies has two categories, action, comedy,
// and comedy has three sections (kevin hart, mike epps, chris rock) and action has three sections (chuck norris, jet li, jackie chan).
// if we were going to insert a document (movie) into the movies collection.
let movieOne = { _id: "Jolade's movie log", path: null } // the path null marks this as a root node
const m = db.movies.insert(movieOne)
//to declare a node to the category
const a = db.movies.insert({ path: `,${m._id},`, _id: "Jolade's movie log (action)" })
// we can use this as an example in video 3
const mapFunction = () => {
// this function will be called with the context of
// this locked to the record in iteration
emit(this.user_name, this.price)
}
// Video 3
const reduceFunction = (key, values) => {
return values.reduce((a, b) => a + b)
{
"questions": {
"Onset Symptoms": [
{
"question": "Do you have a fever or a history of fever?",
"options": [
"Yes",
"No",
"Unknown"
],
import React, { PureComponent } from "react";
// treating this as a parent component that has explicit knowledge of the presentation and behavior of it's
// children
class Dropdown extends PureComponent {
constructor(props) {
super(props);
this.state = {
isOpen: false,
@Hasstrup
Hasstrup / password_strength.rb
Created November 2, 2020 03:08 — forked from lucasdavila/password_strength.rb
Password strength with regex in Ruby
# example of using lookahead assertion to test password strength
# test if a given string contains at least a lowercase letter, a uppercase, a digit, a special char and 8+ chars
strong = "123ABCabc-"
strong[/^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\W]).{8,}$/]
# test if a given string contains at least a lowercase letter, a uppercase, a digit and 8+ chars
medium = "123ABCabc"
medium[/^(?=.*[a-zA-Z])(?=.*[0-9]).{8,}$/]