Skip to content

Instantly share code, notes, and snippets.

View santosh's full-sized avatar
:octocat:

Santosh Kumar santosh

:octocat:
View GitHub Profile
# You are creating a fantasy video game. The data structure to model the player's inventory will be a dictionary where the keys are string values describing the item in the inventory and the value is an integer values defailing how many of that item the player has. For example, the dictionary value {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12} means the player has 1 rope, 6 torches, 42 gold coins, and so on.
# Write a function named displayInventory() that would take any possible "inventory" and display it like the following:
# Inventory:
# 12 arrow
# 42 gold coin
# 1 rope
# 6 torch
# 1 dagger
@santosh
santosh / tictactoe.py
Created January 28, 2019 14:34
Tic-Tac-Toe using Python dictionaries.
# Tic-Tac-Toe game; uses numpad for entries
the_board = {
'7': ' ',
'8': ' ',
'9': ' ',
'4': ' ',
'5': ' ',
'6': ' ',
'1': ' ',
@santosh
santosh / employee.go
Created December 14, 2018 18:00
Classes and constructor in #golang.
package employee
import "fmt"
// employee represents an employee
type employee struct {
firstName string
lastName string
totalLeaves int
leavesTaken int
@santosh
santosh / index.html
Created October 21, 2018 05:06
A facebook login replica, in vanilla js.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript - Replicating Facebook</title>
<script src="script.js" charset="utf-8"></script>
</head>
<body>
<p>You are kinda replicating.</p>
@santosh
santosh / timers.css
Created October 14, 2018 05:50
Working with setInterval and setTimeout in #JavaScript
body {
background: #eee;
}
#message {
width: 400px;
background: #ddaaaa;
padding: 20px;
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
font-size: 18px;
@santosh
santosh / onclick.css
Created October 14, 2018 05:13
Changing class onclick. #JavaScript
body {
background: #eee;
}
#content {
width: 400px;
background: #fff;
padding: 20px;
padding-top: 0;
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
@santosh
santosh / constructorfuncts.js
Created October 13, 2018 02:53
Constructor functions, aka Classes (in other langs)
var Car = function(maxSpeed, driver) {
this.maxSpeed = maxSpeed;
this.driver = driver;
this.drive = function(speed, time) {
console.log(speed, time);
};
this.logDriver = function() {
console.log("driver name is " + this.driver);
};
};
@santosh
santosh / form_validation.html
Last active September 23, 2018 11:06
Basic form validation #JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Form Validation Example</title>
</head>
<body>
<form action="/register" id="registration" method="get" accept-charset="utf-8">
<input type="text" name="email" placeholder="Email" autofocus autocomplete="off" />
@santosh
santosh / main.ts
Created September 12, 2018 16:02
Classes and modules in #TypeScript.
// import syntax is kinda just opposite from Python
import {Point} from './point';
let point = new Point();
let x = point.X;
point.X = 10;
point.draw();
@santosh
santosh / type.ts
Created September 12, 2018 07:19
TypeScript type assertions..
// without initilization, message is of 'any' type
// now you won't get intellisense because editor doesn't
// know what type it is..
let message;
message = "abs";
// one example of type assertion
let endswithC = (<string>message).endsWith('c');
// the alternative way