Skip to content

Instantly share code, notes, and snippets.

View ashishlahoti's full-sized avatar
💭
Live.Love.Laugh

Ashish Kumar Lahoti ashishlahoti

💭
Live.Love.Laugh
View GitHub Profile
package com.example.util;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* Initialize Immutable List
*/
// 1. Java 8 or before
List<String> list1 = Arrays.asList("foo", "bar", "baz");
// 2. Java 9 or later
List<String> list3 = List.of("foo", "bar", "baz");
// 3. Using Streams
def reward_function(params):
'''
Example of rewarding the agent to follow center line
'''
# Read input parameters
track_width = params['track_width']
distance_from_center = params['distance_from_center']
all_wheels_on_track = params['all_wheels_on_track']
speed = params['speed']
@ashishlahoti
ashishlahoti / StopThreadAfterTimeout.java
Last active September 28, 2020 03:08
A Task is running in a separate thread. Stop the task if it exceeds 10 minutes
package com.example.thread;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
@ashishlahoti
ashishlahoti / SemaphoreTest.java
Last active September 28, 2020 01:38
Semaphore is used when you want to limit maximum number of concurrent calls to a particular resource in multi-threaded environment.
package com.example.thread;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
/**
* Semaphore is used when you want to limit maximum number of concurrent calls
@ashishlahoti
ashishlahoti / captialize-string.js
Created June 20, 2020 06:21
How to Capitalize First Letter of String in JavaScript
// es5 way
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// es6 way using destructuring
const capitalize = ([first,...rest]) => first.toUpperCase() + rest.join('');