Skip to content

Instantly share code, notes, and snippets.

View sureshsarda's full-sized avatar
🏠
Working from home

Suresh Sarda sureshsarda

🏠
Working from home
View GitHub Profile
@sureshsarda
sureshsarda / ProxyNewProxyInstanceUsageSimple.java
Created December 23, 2022 11:46
A example using Proxy.newProxyInstance in Java
public class Application {
private interface Interface1 {
void method1();
}
private interface Interface2 {
void method2();
}
@sureshsarda
sureshsarda / RandomTransformer.java
Created July 21, 2020 03:28
Transforming a random number generator to another scale
class RandomTransformer {
private int lastReturned = 0;
public int rand10() {
lastReturned = ((lastReturned + rand7()) % 10) + 1;
return lastReturned;
}
}
@sureshsarda
sureshsarda / StringTo2DArray.java
Created April 15, 2020 03:52
Convert String to Integer and 2D Integer Array
public static class StringTo2DArray implements Function<String, int[][]> {
@Override
public int[][] apply(String s) {
String trimmed = s.trim();
String arraysString = s.substring(1, trimmed.length() - 1);
String[] arrays = arraysString.replaceAll("]\\s*,\\s*\\[", "]\n[")
.split("\n");
@sureshsarda
sureshsarda / imdb-title-subtitle-plot-summary.json
Last active April 6, 2020 02:40
IMDB - Movies Data (Small)
[
{
"title": "Pirates of the Caribbean: Dead Man's Chest",
"tag_line": "Captain Jack is back.",
"plot_summary": "Jack Sparrow races to recover the heart of Davy Jones to avoid enslaving his soul to Jones' service, as other friends and foes seek the heart for their own agenda as well."
},
{
"title": "Pirates of the Caribbean: At World's End",
"tag_line": "At the End of the World, the Adventure Begins",
"plot_summary": "Captain Barbossa, Will Turner and Elizabeth Swann must sail off the edge of the map, navigate treachery and betrayal, find Jack Sparrow, and make their final alliances for one last decisive battle."
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sureshsarda
sureshsarda / hardownload.py
Created October 4, 2018 01:25
Download the network tab content when loading a page
import time
import pprint
from selenium import webdriver
from browsermobproxy import Server
class Browser:
def __init__(self):
self.server = None
self.profile = None
@sureshsarda
sureshsarda / Primes.java
Last active May 10, 2018 01:51
TestGist.java
public static void main(String[] args) throws Exception {
int p = 43; // very large prime number
int q = 59; // very large prime number
int n = p * q;
int p1q1 = (p - 1) * (q - 1);
int e = 13; // gcd(e, p1a1) = 1
String message = "HELLO";
byte[] bytes = message.getBytes();
for (int i = 0; i < bytes.length; i++) {
@sureshsarda
sureshsarda / basic_logging.py
Created September 23, 2017 04:55
Boiler plate code for every file to start with logging
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.debug('Hello, Logging!')