Skip to content

Instantly share code, notes, and snippets.

Avatar

Santosh Kumar santosh

View GitHub Profile
@santosh
santosh / printflush.py
Created Mar 25, 2013
This script demonstrate the `flush` argument of print() function.
View printflush.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from __future__ import print_function
from time import sleep
string = "The words in this sentence should appear letter by letter."
print("Please wait if you don't see another sentence appearing below.", end="\n\n")
@santosh
santosh / connectionpool.py
Last active Aug 24, 2021
Connection pooling with PostgreSQL in Python.
View connectionpool.py
from psycopg2.extras import DictCursor
from psycopg2.pool import SimpleConnectionPool
class Database:
__pool = None
@classmethod
def initialize(cls, **kwargs):
cls.__pool = SimpleConnectionPool(minconn=2,
@santosh
santosh / AsteroidGrid.js
Created Aug 2, 2021
Event passing to parent and back.
View AsteroidGrid.js
// requires Vue.js and Bootstrap
Vue.component('asteroid-grid', {
props: ['asteroids', 'header'],
data: function () {
return {
showSummary: true
}
},
computed: {
numAsteroids: function () {
@santosh
santosh / vue.html
Created Aug 2, 2021
Fetching API, handing events, doing CSS animations.
View vue.html
<!DOCTYPE html>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<style>
[v-clock] {
display: none;
}
.highlight {
border: solid 3px red;
color: 'red'
@santosh
santosh / vue.html
Created Aug 2, 2021
Props and slots. Slot scopes.
View vue.html
<!DOCTYPE html>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<style>
[v-cloak] {
display: none;
}
</style>
<div id="app">
@santosh
santosh / vue.html
Created Aug 2, 2021
Fetching API, handing events, doing CSS animations.
View vue.html
<!DOCTYPE html>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<style>
[v-clock] {
display: none;
}
.highlight {
border: solid 3px red;
color: 'red'
@santosh
santosh / main.go
Created Jun 17, 2021
Multiplexing concurrency pattern
View main.go
package main
import (
"fmt"
"math/rand"
"time"
)
func boring(msg string) <-chan string { // Returns receive-only channel of strings.
c := make(chan string)
@santosh
santosh / main.go
Created Jun 17, 2021
Generator concurrency pattern.
View main.go
package main
import (
"fmt"
"math/rand"
"time"
)
func boring(msg string) <-chan string { // Returns receive-only channel of strings.
c := make(chan string)
@santosh
santosh / main.go
Last active Jun 17, 2021
progressively learning goroutines
View main.go
package main
import (
"fmt"
"math/rand"
"time"
)
func boring(msg string, c chan string) {
for i := 0; ; i++ {
@santosh
santosh / index1.html
Created Apr 16, 2021
CSS Grid for beginners.
View index1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Grid</title>
<style>
.container {
display: grid;