Skip to content

Instantly share code, notes, and snippets.

View chirag-shinde's full-sized avatar
💾
learning, unlearning & relearning!

Chirag Shinde chirag-shinde

💾
learning, unlearning & relearning!
View GitHub Profile
@chirag-shinde
chirag-shinde / rock_paper_scissor_rope.js
Last active August 29, 2015 14:26
CodeAcademy's JavaScript Rock,Paper,Scissors, Rope. This does all the 3, check the user's input, added choice of rope, in case of a tie it asks users or new input.
var choice = function()
{
var userChoice = prompt("Select rock, paper, scissors,rope");
if(userChoice!=="rock" && userChoice!=="paper" && userChoice!=="scissors" && userChoice!=="rope")
{
alert("You have entered wrong choice, enter rock, paper, scissors or rope");
choice();
}
else{
var computerChoice = Math.random();
@chirag-shinde
chirag-shinde / uploadMethodOne.php
Created October 23, 2015 13:09
PHP Script to Upload CSV to MongoDB. Method One of Two.
<?php
//Your Database Connection include file here.
//This Entire PHP part can be placed in a seperate action file
//Upload File
if (isset($_POST['submit'])) {
//Upload Directory path.
$uploaddir = 'uploads/';
//FilePath with File name.
$uploadfile = $uploaddir . basename($_FILES["filename"]["name"]);
@chirag-shinde
chirag-shinde / uploadMethodTwo.php
Last active April 21, 2021 07:39
PHP Script to Upload CSV to MongoDB. Method Two of Two.
<!-- MongoDB has a command named mongoimport which can be used to directly upload a CSV file into a particular collection of
a database with the first line of the csv as the keys and the following rest of the csv as the values for the respective keys
The format of mongoimport is as folllows
"mongoimport --db database_name --collection collection_name --file csv_file_name --type csv"
now we can use variables to store our database and collection's name.
we upload the file to get the filename and it's path and then simple substitute the database_name and collection_name etc
class Solution:
def singleNumber(self, nums: List[int]) -> int:
return reduce( lambda x, y: x ^ y, nums)
class Solution:
def singleNumber(self, nums: List[int]) -> int:
nums_set = set()
for num in nums:
if num in nums_set:
nums_set.remove(num)
else:
nums_set.add(num)
return nums_set.pop()
class Solution:
def sum_of_squares(self, n: int) -> int:
total = 0
while n > 0:
total += (n % 10) ** 2
n = int(n / 10)
return total
def isHappy(self, n: int) -> bool:
repeat_numbers = set()
class Solution:
def sum_of_squares(self, n: int) -> int:
total = 0
while n > 0:
total += (n % 10) ** 2
n = int(n / 10)
return total
def isHappy(self, n: int) -> bool:
fast = self.sum_of_squares(n)
def insertion_sort(list: [int]) -> [int]:
for i in range(1, len(list)):
element = list[i]
j = i - 1
while j >= 0 and element < list[j]:
list[j + 1] = list[j]
j -= 1
list[j + 1] = element
return list
def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
left = arr[:mid]
right = arr[mid:]
merge_sort(left)
merge_sort(right)
merge(arr,left,right)
def merge(arr, left, right):
def quick_sort(arr,start, end):
if start < end:
pivot = partition(arr, start, end)
quick_sort(arr, start, pivot - 1)
quick_sort(arr, pivot + 1, end)
def partition(arr, start, end):
element = arr[start]
i = start
for j in range(start + 1, end):