Skip to content

Instantly share code, notes, and snippets.

View rbrahul's full-sized avatar

Rahul Baruri rbrahul

View GitHub Profile
@rbrahul
rbrahul / multiple-file-build-with-vite.js
Created April 3, 2024 21:50
Generating Multiple File build in Vitejs
import { defineConfig } from "vite";
function getDirFromAsset(assetInfo) {
if(!assetInfo.name){
return "assets"
}
else if (assetInfo.name.endsWith("css")) {
return "css";
} else if (assetInfo.name.endsWith("js")) {
return "js";
@rbrahul
rbrahul / StateHistory.js
Created May 13, 2023 22:36
Simple implementation of Undo and Redo With State History
class StateHistory{
historyIndex = 0;
initialState = {num: 1};
stateHistory = [this.initialState];
setState(fn){
this.stateHistory = [...this.stateHistory, fn(this.stateHistory[this.historyIndex])];
this.historyIndex++;
}
@rbrahul
rbrahul / EventHandler.go
Last active May 6, 2023 17:36
Custom event handling in Golang
package main
import (
"fmt"
"time"
)
type EventType interface {
AddEventListener(string, func(interface{}))
Trigger(string, interface{})
@rbrahul
rbrahul / chrome_storage_polyfill.js
Last active August 22, 2022 06:40
This Polyfill provides basic support for chrome.storage.sync and chrome.storage.local API outside of chrome extension runtime
const chromeStoragePolyfill = function (dbName) {
const STORAGE_PREFIX = "CHROME_STORAGE_API_WRAPPER_DB";
let __db__;
const _getData = () => {
const jsonData = window.localStorage.getItem(__db__);
if (jsonData) {
return JSON.parse(jsonData);
}
};
@rbrahul
rbrahul / index.html
Created August 13, 2020 20:51
JS Bin Color Palater // source https://jsbin.com/dixubur
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Color Palater">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
select wp.ID, wpm.meta_value from wp_posts wp INNER JOIN `wp_postmeta` wpm ON wp.ID = wpm.`post_id`
WHERE wp.`post_type` = 'product' AND wpm.`meta_key`='_amzASIN'
select * from wp_posts where match(post_title, post_content) AGAINST ('best iphone to buy')
#ALTER TABLE wp_posts ADD FULLTEXT(post_title, post_content)
@rbrahul
rbrahul / Asin-grabber.html
Created April 4, 2019 09:35
Grab all ASINs from all countries from Amazon using one ASIN
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="ASIN GRABBER">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
@rbrahul
rbrahul / Capture-Youtube-Video.js
Last active November 13, 2023 01:30
Capture Screenshot from Youtube Video
var canvas = document.createElement('canvas');
canvas.width = 640;
canvas.height = 480;
var ctx = canvas.getContext('2d');
var video = document.querySelector(".html5-video-container > video");
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
var dataURI = canvas.toDataURL('image/jpeg');
console.log(dataURI);
@rbrahul
rbrahul / battery.js
Last active May 25, 2018 14:58
Javascirpt Battery Status Browser API
function updateChargeInfo(battery) {
var message = battery.charging ? "Charging now :D": "Need Charge" ;
var batteryStatusNode = document.querySelector('.charging-status');
var classes = batteryStatusNode.classList;
document.querySelector('#message').innerHTML =message;
if(battery.charging) {
if (classes.contains('charging') === false) {
classes.add('charging');
classes.remove('not-charging');