Skip to content

Instantly share code, notes, and snippets.

View naveed125's full-sized avatar

Naveed Khan naveed125

View GitHub Profile
@naveed125
naveed125 / docker-compose.yml
Created May 2, 2020 20:12
Docker Compose File for React and Flask Application
version: '3'
services:
client:
build: client
stdin_open: true
ports:
- 80:3000
volumes:
@naveed125
naveed125 / Dockerfile
Created May 2, 2020 20:08
Flask Server Dockerfile
FROM python:3.8.2-alpine
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
@naveed125
naveed125 / Dockerfile
Created May 2, 2020 20:03
Client Dockerfile for React Application
FROM node:13.12.0-alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app
RUN npm install --silent
COPY . /app
@naveed125
naveed125 / deliver-on-check.php
Last active May 2, 2020 04:06
Deliver on check to avoid background processing
<?php
/**
* Wizard represents an object that generates mana over time
*/
class Wizard {
private $mana = 0;
private $last_checked = 0;
@naveed125
naveed125 / redis-consumer.php
Created March 13, 2020 05:29
Redis pubsub consumer example
<?php
// uses Predis see https://github.com/nrk/predis
$client = new Predis\Client();
// connect to the local redis server
$client->connect();
// wait for messages on channel and print them on screen
echo("Waiting for messages on channel.\n");
@naveed125
naveed125 / redis-producer.php
Created March 13, 2020 05:27
Redis pubsub producer example
<?php
// uses Predis see https://github.com/nrk/predis
$client = new Predis\Client();
// connect to the local redis server
$client->connect();
// Read input from user and send to channel
echo "Press CTRL-C to stop.\n";
@naveed125
naveed125 / redis-db-cache.php
Created March 13, 2020 00:00
Redis Object Cache with Mock Database
<?php
require __DIR__ . '/../vendor/autoload.php';
// uses Predis https://github.com/nrk/predis
use Predis\Client as PredisClient;
$user = get_user(125);
print_r($user);
@naveed125
naveed125 / redis-lock.php
Created March 12, 2020 05:54
Sample code showing usage of SET with NX to acquire a semaphore lock
<?php
// uses Predis
// see https://github.com/nrk/predis
use Predis\Client as PredisClient;
$client = new PredisClient();
// connect to the local redis server
$client->connect();
@naveed125
naveed125 / redis-counter.php
Created March 12, 2020 05:26
Sample code showing redis INCR command usage
<?php
// uses Predis
// see https://github.com/nrk/predis
$client = new Predis\Client();
// connect to the local redis server
$client->connect();
// increment the counter in a loop
for($i=0;$i<10;$i++) {
@naveed125
naveed125 / redis-leaderboard.php
Last active January 10, 2022 03:42
A simple leaderboard implementation using redis and PHP
<?php
// uses Predis https://github.com/nrk/predis
$client = new Predis\Client();
// connect to the local redis server
$client->connect();
// delete any existing key
$key = 'leaderboard';
$client->del([$key]);