Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Live.Love.Laugh

Ashish Kumar Lahoti ashishlahoti

💭
Live.Love.Laugh
View GitHub Profile
@ashishlahoti
ashishlahoti / captialize-string.js
Created Jun 20, 2020
How to Capitalize First Letter of String in JavaScript
View captialize-string.js
// 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('');
View aws-deepracer-reward-function.py
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']
View initialize-list-with-values-in-java.java
/**
* 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
@ashishlahoti
ashishlahoti / SemaphoreTest.java
Last active Sep 28, 2020
Semaphore is used when you want to limit maximum number of concurrent calls to a particular resource in multi-threaded environment.
View SemaphoreTest.java
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 / StopThreadAfterTimeout.java
Last active Sep 28, 2020
A Task is running in a separate thread. Stop the task if it exceeds 10 minutes
View StopThreadAfterTimeout.java
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;
/**
View ZipFileUtil.java
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;