Skip to content

Instantly share code, notes, and snippets.

View satya-jugran's full-sized avatar

Satya Jugran satya-jugran

  • India
View GitHub Profile
@satya-jugran
satya-jugran / roulette.py
Created November 6, 2017 15:24
Python code for Roulette wheel selection
#!/usr/bin/env python
import sys, time, numpy, random
# Individual has a genome and fitness and knows how to print itself
class Individual:
def __init__(self, genome):
if genome is None:
self.genome = numpy.array(numpy.random.random_integers(0, 1, LEN), dtype='bool')
else:
@satya-jugran
satya-jugran / MostFreeTime.js
Created September 21, 2018 15:34
Find most free time of the day. Input string will represent full day filled with events that span from time X to time Y. Test case : 1) Input - "12:15PM-02:00PM","09:00AM-10:00AM","10:30AM-12:00PM" | Output - 00:30 2) Input - "12:15PM-02:00PM","09:00AM-12:11PM","02:02PM-04:00PM" | Output - 00:04
function MostFreeTime(str) {
var dates = [];
str.split(",").forEach(d => {
dt = d.substring(1, d.length - 1).split("-");
s = dt[0];
dt[0] = s.substr(s.length - 2, 2) == "AM" ? s.substr(0, 5) :
(Number.parseInt(s.substr(0, 2)) < 12 ? Number.parseInt(s.substr(0, 2)) + 12 + ":" + s.substr(3, 2) : s.substr(0, 5));
s = dt[1];
@satya-jugran
satya-jugran / GeoLocation.html
Created March 27, 2017 17:13
Code to view current location on Google Maps using HTML5 Geolocation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="geo-wrapper" width="600" height="400"></div>
<span id="geo-error"></span>