Skip to content

Instantly share code, notes, and snippets.

Avatar

Naveed Khan naveed125

View GitHub Profile
@naveed125
naveed125 / docker-compose.yml
Created May 2, 2020
Docker Compose File for React and Flask Application
View docker-compose.yml
version: '3'
services:
client:
build: client
stdin_open: true
ports:
- 80:3000
volumes:
@naveed125
naveed125 / Dockerfile
Created May 2, 2020
Flask Server Dockerfile
View 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
Client Dockerfile for React Application
View Dockerfile
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
Deliver on check to avoid background processing
View deliver-on-check.php
<?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 Mar 13, 2020
Redis pubsub consumer example
View redis-consumer.php
<?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 Mar 13, 2020
Redis pubsub producer example
View redis-producer.php
<?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 Mar 13, 2020
Redis Object Cache with Mock Database
View redis-db-cache.php
<?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 Mar 12, 2020
Sample code showing usage of SET with NX to acquire a semaphore lock
View redis-lock.php
<?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 Mar 12, 2020
Sample code showing redis INCR command usage
View redis-counter.php
<?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 Jan 10, 2022
A simple leaderboard implementation using redis and PHP
View redis-leaderboard.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]);