Skip to content

Instantly share code, notes, and snippets.

A58
---
A [Pen](https://codepen.io/zilveer/pen/xbGNKeQ) by [zilveer](https://codepen.io/zilveer) on [CodePen](https://codepen.io).
[License](https://codepen.io/license/pen/xbGNKeQ).
@zilveer
zilveer / demo.php
Created November 19, 2024 06:55 — forked from freekrai/demo.php
PHP session-based rate limiter for APIs
<?php
date_default_timezone_set('America/Los_Angeles');
session_start();
include("ratelimiter.php");
// in this sample, we are using the originating IP, but you can modify to use API keys, or tokens or what-have-you.
$rateLimiter = new RateLimiter($_SERVER["REMOTE_ADDR"]);
$limit = 100; // number of connections to limit user to per $minutes
$minutes = 1; // number of $minutes to check for.
@zilveer
zilveer / incremental-game-loop.md
Created November 4, 2024 07:23 — forked from HipHopHuman/incremental-game-loop.md
How to make a game loop for your idle game

How do I make a game loop for my Idle Game?

Interval-Based Resource Generators

So, you want to build an idle/incremental game in JavaScript and you’ve read on the internet that setInterval is the way to go when it comes to handling resources that automatically generate over time.

You get started, you write down your setInterval function, you set it to trigger once every 1000 milliseconds, and every time it triggers, you add 1 to the player’s total resource count. Perfect. It works.

Uh-oh.

@zilveer
zilveer / verifyTelegramWebAppData.tsx
Created October 27, 2024 22:48 — forked from konstantin24121/verifyTelegramWebAppData.tsx
Telegram Bot 6.0 Validating data received via the Web App node implementation
const TELEGRAM_BOT_TOKEN = '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw'; // https://core.telegram.org/bots#creating-a-new-bot
export const verifyTelegramWebAppData = async (telegramInitData: string): boolean => {
// The data is a query string, which is composed of a series of field-value pairs.
const encoded = decodeURIComponent(telegramInitData);
// HMAC-SHA-256 signature of the bot's token with the constant string WebAppData used as a key.
const secret = crypto
@zilveer
zilveer / telegram.php
Created October 26, 2024 10:25 — forked from fmkoc/telegram.php
Login with Telegram | PHP Guide
<?php
define('TELEGRAM_BOT', 'YOUR_BOT'); // Username of the bot (Generated on @BotFather)
define('TELEGRAM_TOKEN', 'YOUR:TOKEN'); // Token of the bot (Generated by @BotFather)
//Data validation function
function checkTelegramAuthorization($auth_data) {
$check_hash = $auth_data['hash'];
unset($auth_data['hash']);
$data_check_arr = [];
foreach ($auth_data as $key => $value) {
@zilveer
zilveer / router.html
Created January 15, 2023 12:12 — forked from joakimbeng/router.html
A really simple Javascript router
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Building a router</title>
<script>
// Put John's template engine code here...
(function () {
// A hash to store our routes:

Usecase - Integrating Anoncoin to Coinomi

A simple usecase of a Bitcoin compatible coin integration. Not all coins are created equal, so it is possible that extra work must be done to successfully integrate a new cryptocurrency.

  1. Start the Anoncoin daemon and in the anoncoin.conf file add the option "txindex=1"
rpcuser=anoncoinrpc
rpcpassword=MFfySYp9o9qQi0mYbQmxOdE1pEHVS1DQuhhHssOzkO3
rpcport=8022
function getList(idxSoul,cb){
let listOfSouls = {}
let soulsToCheckAgainstUnique = []
gun.get(idxSoul).once(function(data){
if(data === undefined){cb.call(cb,listOfSouls); return}//for loop would error if not stopped
for (const soul in data) {
if(soul === '_')continue
if(data[soul] !== null){//not Deleted
//this means `false` will pass through, so archived items will still keep increment and unique values enforced
soulsToCheckAgainstUnique.push(soul)
@zilveer
zilveer / bootstrap.toggleModal.js
Created June 6, 2022 13:18 — forked from todofixthis/bootstrap.toggleModal.js
Shows/Hides a Bootstrap 3 modal and returns a Promise object.
/** Shows or hides a Bootstrap 3 modal and returns a Promise object.
*
* Bootstrap's modal functions return before the modal is shown/
* hidden, which can cause glitches if subsequent code doesn't
* expect that.
*
* Unfortunately, there is no built-in way to defer an
* operation until after the modal is shown/hidden, so
* this function does a little monkey-patching to make
* it work.
@zilveer
zilveer / swipe.js
Created June 3, 2022 16:36 — forked from SleepWalker/swipe.js
A simple swipe detection on vanilla js
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var gesuredZone = document.getElementById('gesuredZone');
gesuredZone.addEventListener('touchstart', function(event) {
touchstartX = event.screenX;
touchstartY = event.screenY;