Skip to content

Instantly share code, notes, and snippets.

View mayanksha's full-sized avatar
🎯
Focusing

Mayank Sharma mayanksha

🎯
Focusing
View GitHub Profile
@mayanksha
mayanksha / modifiedEventListenerFunctions.ts
Created December 4, 2023 06:44
Fetching event listeners for an HTMLElement in Javascript
const listeners: any[] = [];
const orig = EventTarget.prototype.addEventListener;
const orig2 = EventTarget.prototype.removeEventListener;
EventTarget.prototype.addEventListener = function(...args) {
if (this instanceof HTMLElement) {
listeners.push({
type: args[0],
fn: args[1],
@mayanksha
mayanksha / lvalue-reference-no-copy.cpp
Created June 26, 2022 15:20
Whenever creating a temporary variable for any STL container, store it in an lvalue reference instead of an lvalue. Using an lvalue would call the copy constructor instead and you'd end up with a deep copy of the object which is not what you might have intended.
// You can run this benchmark on https://quick-bench.com/q/ljaOsHxNAiH3bHORVKnpVndb0lQ
// The non-copy example is almost 20000 times faster than the copy example (which is kinda expected)
// but I just wanted to test it out.
struct Temp {
public:
std::vector<int> v;
std::string s;
Temp() {
@mayanksha
mayanksha / logback.xml
Created April 4, 2022 12:30
logback.xml with colored output and setting up logger with TRACE output
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<!-- NON-COLORED OUTPUT -->
<!-- <Pattern>%d{HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</Pattern>-->
<!-- COLORED OUTPUT -->
<Pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</Pattern>
</layout>
@mayanksha
mayanksha / socket-server.java
Created May 11, 2021 10:13
Simple Socket Server in Java
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.StringTokenizer;
@mayanksha
mayanksha / bsnl-ftth-gpon-autofill-captcha.js
Created April 17, 2021 15:50
Automatically fills the standard password and captcha for the BSNL GPON router page
(function() {
'use strict';
setTimeout(() => {
document.querySelector("#inputCode").value = code;
document.querySelector("#Password").value = "bsnl@321";
}, 50);
})();

Workflow for handling migration changes and local development setup

Let's make an initial assumption: We have a staging database that is up to date with production (in terms of schema). Now, a new developer comes to the company and he wants to setup his own dev environment (let's say from the staging database's schema). The code development workflow is pretty standard i.e. develop locally, push to repo

For local database setup, what we need is to perform a migration from the staging database to the local development database. The developer can pull a hasura-postgresql docker image and run Hasura in a container.

For the actual migration, hasura's console comes to our rescue. Firstly, the developer needs to create a new hasura migration or maybe use some existing ones from a git repo, the latter being more favorable. So, assuming that staging database has a git repo which gets updated daily (i.e. a new version of migration gets created every day), the developer can pull this database, simply change t

systemctl stop nginx && certbot certonly --standalone --preferred-challenges http -d msharma.in -d www.msharma.in && systemctl start nginx
+ error = NULL;
+
+ if (!g_file_query_exists (dest, job->cancellable))
+ {
+ const gchar *src_display_name;
+ GFileInfo *info = NULL;
+ g_autoptr (GMount) mount_point = NULL;
+
+ if ((mount_point = g_file_find_enclosing_mount (src, job->cancellable, &error)) != NULL)
+ {
@mayanksha
mayanksha / gist:a8817c94437e157bce10539dc0d0d499
Created December 4, 2019 08:45
Create a new dummy test file using GIO and libgdata (for Google Drive)
static GDataDocumentsEntry *
create_dummy_test_file (GDataDocumentsService *service, GDataDocumentsEntry *parent, GError **error)
{
static guint dummy_file_counter = 0;
const gchar *buf = "Foobar";
gssize bytes_written;
GDataDocumentsDocument *new_document = NULL;
GDataUploadStream *ostream = NULL;
g_autofree gchar *counter_buf = NULL;
g_autofree gchar *title = NULL;
typedef struct
{
GAsyncResult *res;
GMainLoop *loop;
} MountData;
static void
volume_mount_cb (GVolume *volume,