Skip to content

Instantly share code, notes, and snippets.

View savannahar68's full-sized avatar
πŸ‘¨β€πŸ’»
Creating Bugs :p

Savan Nahar savannahar68

πŸ‘¨β€πŸ’»
Creating Bugs :p
View GitHub Profile
@savannahar68
savannahar68 / converter.go
Last active April 15, 2023 08:54
Proto struct value to golang interface (and vice versa) converter
// The function uses reflection to convert Proto struct to interface and vice versa.
// Although reflection is CPU intensive, the code is optimised to short circuit at most of the places to convert in most optimal way
package converter
import (
"reflect"
"strconv"
"google.golang.org/protobuf/types/known/structpb"
)
@savannahar68
savannahar68 / Singleton.java
Created March 14, 2022 16:27
Easiest way of creating a Singleton in Java (Using ENUM - Thread Safe, Lazily initialized and created on invocation)
public enum Singleton {
INSTANCE;
// Add your methods here
public void getString() {
System.out.println("Hi");
}
// Invoke singleton from main method present in any class
public static void main(String[] args) {
@savannahar68
savannahar68 / Paypal.tsx
Created October 9, 2021 10:57
react-paypal-js integration with your backend
<PayPalScriptProvider options={initialOptions}>
<PayPalButtons
style={{ layout: "horizontal" }}
createOrder={async (data, actions) => {
try {
const orderId = await generateOrder(Id, currency);
setOrderId(orderId);
return orderId;
} catch {
Toastr.error("Error Creating Paypal Order");
@savannahar68
savannahar68 / webflowPackage.html
Created September 18, 2021 06:29
Webflow Package JS
<script type="text/javascript">
(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&(a=a[b[0]],d=b[1]);a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var a=b;"undefined"!==typeof c?a=b[c]=[]:c="mixpanel";a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);a||(d+=" (stub)");return d};a.people.toString=function(){return a.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" ");
for(h=0;h<i.length;h++)g(a,i[h]);
@savannahar68
savannahar68 / webflowClickTrackerCustomJs.html
Last active September 18, 2021 06:27
Webflow Custom JS
<script type="text/javascript">
$(document).ready(function() {
$(document).on('click', '[data-tracker]', function(e) {
var trackData = $(this).data('tracker');
if (!trackData) { return; }
var tagData = ParseTagData.tagData(trackData);
if (!tagData.action || !tagData.label ) { return; }
@savannahar68
savannahar68 / webflowPageViewCustomJs.html
Created September 18, 2021 06:21
Webflow Page View Custom JS
<script type="text/javascript">
mixpanel.track('page viewed', {
'page name' : document.title,
'url' : window.location.pathname
});</script>
@savannahar68
savannahar68 / maasExample.py
Created July 1, 2020 04:37
GET POST Example for MaaS API - Python
import json
from requests import Request, Session
from requests_oauthlib import OAuth1
# <consumer_key>:<token_key>:<token_secret>
# xxxxxxxxxxxxxx:yyyyyyyyyyy:zzzzzzzzzzzzzz
# Replace the below key and secret string with actual one
auth1 = OAuth1(u'consumer_key', u'',
@savannahar68
savannahar68 / shell.c
Last active June 30, 2020 01:23
Terminal/CMD with just 6 lines of code
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
int main(){
int pid;
char cmd[128];
while(1){
printf("prompt>");