Skip to content

Instantly share code, notes, and snippets.

View santosh's full-sized avatar
:octocat:

Santosh Kumar santosh

:octocat:
View GitHub Profile
@santosh
santosh / data.txt
Last active September 10, 2020 18:05
Plotting in Go with gonum/plot.
6.1101,17.592
5.5277,9.1302
8.5186,13.662
7.0032,11.854
5.8598,6.8233
8.3829,11.886
7.4764,4.3483
8.5781,12
6.4862,6.5987
5.0546,3.8166
@santosh
santosh / github.go
Last active September 5, 2020 05:13
Webpage OAuth flow example with GitHub.
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
const clientID = "<your client id here>"
@santosh
santosh / worker_pool.go
Created August 18, 2020 04:47
Worker pool with buffered channel.
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
// Worker pool is a collection of threads which are waiting
  • Add concurrency.
  • Now deal with it.
  • Mutexes, somaphores, context switching
  • Check for race condition.
@santosh
santosh / interface.go
Last active July 7, 2020 19:33
Getting started with interfaces.
package main
import "fmt"
type SalaryCalculator interface {
CalculateSalary() int
}
type Permanent struct {
empId int
@santosh
santosh / docker_postgres.md
Last active May 20, 2020 19:30
Basic docker postgres setup for dev.
docker run -d --name postgres -e POSTGRES_PASSWORD=Pass2020! -v postgres-data:/var/lib/postgresql/data -p 5432:5432 postgres:11-alpine

More env vars at https://hub.docker.com/_/postgres.

Hop into the container:

docker exec -it postgres bash

And use the psql repl.

@santosh
santosh / description.md
Created April 29, 2020 18:05
How to test this func in handler.go?

I can run those tests on my local machine where I have mongo instance spinned up. But what about CI/CD services like Travis-CI?

How do I approach this?

@santosh
santosh / usestate.js
Created March 16, 2020 05:13
Using states in functional components.
function App() {
const [count, setCount] = React.useState(0)
function increment() {
setCount(prevCount => prevCount + 1)
}
function decrement() {
setCount(prevCount => prevCount - 1)
}
@santosh
santosh / reactforms.js
Created March 11, 2020 09:27
React Forms.
class App extends React.Component {
constructor() {
super()
this.state = {
firstName: "",
lastName: "",
age: null,
location: "",
gender: "",
dietaryRestrictions: {
@santosh
santosh / apicall.js
Created March 9, 2020 15:41
Fetching data from within #React component. Loading component can be added for smooth transition.
class App extends React.Component {
constructor() {
super()
this.state = {
character: {}
}
}
componentDidMount() {
this.setState({ loading: true })