Skip to content

Instantly share code, notes, and snippets.

View Thecarisma's full-sized avatar
👽

A Thecarisma

👽
View GitHub Profile
@isocroft
isocroft / detecting_navigation_direction_in_spas.js
Last active July 7, 2023 17:23
Monkey-patch on the History interface
/**
* Algorithm {getNavDirection} created by @isocroft
*
* Copyright (c) 2021-2023 | Ifeora Okechukwu
*
* Works in ReactJS / VueJS / jQuery / Angular / Vanilla
*
* Algo implmented in Javascript: used to determine the direction
* of a single-page app navigation to track "Rage Refreshes" and to
* determine when the user visits a page from the back/forward button
@ogwurujohnson
ogwurujohnson / MultiSigWallet.sol
Created April 24, 2020 16:44
A multi signatory smart contract for sending funds on the block chain
pragma solidity ^0.4.0;
pragma experimental ABIEncoderV2;
contract MultiSigWallet {
uint minApprovers;
address beneficiary;
address owner;
mapping(address => bool) approvedBy;
@ogwurujohnson
ogwurujohnson / Voter.sol
Created April 23, 2020 08:46
An ethereum voting smart contract
pragma solidity ^0.4.0;
pragma experimental ABIEncoderV2;
contract Voter {
struct OptionPos {
uint pos;
bool exists;
}
@EvanBacon
EvanBacon / 🧽.gif
Last active June 19, 2024 15:43
🥓
🧽.gif
@Thecarisma
Thecarisma / monitorpod.bat
Last active December 12, 2022 15:31
A batch script to monitor a kubernetes pod status, it shows windows toast notification when the pod status changes. Change the NAME to your pod name.
@echo off
setlocal enabledelayedexpansion
REM Listen for kubenetes pod status changes,
REM change the value of NAME to your pod name or unique
REM part of the name, if more than one pod has the unique
REM part there will be conflict in the log
REM or you can set the pod name from commandline
REM
REM $ monitorpod podname apodnamespace anotherpodname apodpartname
@Thecarisma
Thecarisma / sendwintoast.ps1
Created January 31, 2020 11:23
A Powershell script to send Windows Toast notification. Usage: sendwintoast.ps1 "Your Title" "Your Message" Info
Param([string]$Title,[string]$Message,[string]$MessageType)
Add-Type -AssemblyName System.Windows.Forms
$global:balloon = New-Object System.Windows.Forms.NotifyIcon
Get-Member -InputObject $Global:balloon 2>&1 | Out-Null
[void](Register-ObjectEvent -InputObject $balloon -EventName MouseDoubleClick -SourceIdentifier IconClicked -Action {
$global:balloon.dispose()
})
$path = (Get-Process -id $pid).Path
$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
[System.Windows.Forms.ToolTipIcon] | Get-Member -Static -Type Property 2>&1 | Out-Null
@dumebi
dumebi / Algorithm
Created January 27, 2020 20:52
sample algorithm question
Commander Lambda uses an automated algorithm to assign minions randomly to tasks, in order to keep her minions on their toes. But you've noticed a flaw in the algorithm - it eventually loops back on itself, so that instead of assigning new minions as it iterates, it gets stuck in a cycle of values so that the same minions end up doing the same tasks over and over again. You think proving this to Commander Lambda will help you make a case for your next promotion.
You have worked out that the algorithm has the following process:
1) Start with a random minion ID n, which is a nonnegative integer of length k in base b
2) Define x and y as integers of length k. x has the digits of n in descending order, and y has the digits of n in ascending order
3) Define z = x - y. Add leading zeros to z to maintain length k if necessary
4) Assign n = z to get the next minion ID, and go back to step 2
For example, given minion ID n = 1211, k = 4, b = 10, then x = 2111, y = 1112 and z = 2111 - 1112 = 0999. Then the next m
@Thecarisma
Thecarisma / async-script-loader.js
Last active December 31, 2019 21:37
Load a remote javascript file in the browser synchronously. Wait till loading complete with callback.
//Example: log 'Hello World' after language-colors.css load completed
/**
loadScript("https://quickutils.github.io/language-colors/language-colors.css", function() {
console.log('Hello World');
});
**/
function loadScript(url, callback) {
var head = document.body;
var script = document.createElement('script');
@Thecarisma
Thecarisma / device-enabler.bat
Created December 28, 2019 22:05
Use brute-force method to enable a device when disabled by device control programs (e.g anti-virus). This simple script can be used to activate a disk drive even if a device control program is up.
@echo off
REM download the microsoft devcon app https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/devcon
REM Download x64 if your arch is x64 same for x32
REM change this 'USBSTOR\DISK&VEN_WD&PROD_ELEMENTS_25A2&REV_1021\57584131413438324C384543&0' to your device instace path
REM Run as Administrator
:exec
devcon enable @"USBSTOR\DISK&VEN_WD&PROD_ELEMENTS_25A2&REV_1021\57584131413438324C384543&0"
goto:exec
@Thecarisma
Thecarisma / playground.rs
Created December 15, 2019 21:47 — forked from rust-play/playground.rs
Code shared from the Rust Playground
pub fn reverse_string(s: &mut Vec<char>) {
if s.len() <= 1 {
return;
}
let mut i = 0;
let mut j = s.len() - 1;
while i != j && i < j {
s.swap(i, j);
i += 1;
j -= 1;