Skip to content

Instantly share code, notes, and snippets.

@raj454raj
raj454raj / redis-streams.md
Last active September 2, 2021 09:35
Redis streams cheatsheet
Commands Description
XADD mystream * message 1 Add to stream to insert {message: 1}
XLEN mystream Length of messages in mystream
XRANGE mystream - + COUNT 2 Return the first two elements
XREAD COUNT 2 STREAMS mystream 0 Read 2 elements in stream from the beginning
XREAD BLOCK 0 STREAMS mystream $ Wait indefinitely until a message
XREAD BLOCK 1000 STREAMS mystream $ Wait for 1 second for a message else timeout
XGROUP CREATE mystream group1 $ Create a group1 in consumer group in a stream
XREADGROUP GROUP group1 cons1 COUNT 1 STREAMS mystream > Consume new messages as cons1 in group1 and get all the new messages
res = DEFAULT_REDIS_CLIENT.slowlog("GET", 128)
puts "Timestamp,Command,Time taken (in seconds)"
res.each do |one_list_item|
puts "\"#{Time.at(one_list_item[1])}\",\"#{one_list_item[3].join(' ')}\",#{one_list_item[2]*1.0/1000000}"
end
@raj454raj
raj454raj / http_client_comparison.rb
Created January 7, 2019 18:50
Show net/http module retries if the first one timed out over typhoeus
require 'net/http'
require 'uri'
require 'typhoeus'
def get_response(url, request_timeout)
# Raises exception on timeout
url = URI(url)
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new url
http.read_timeout = request_timeout
@raj454raj
raj454raj / app.js
Created January 7, 2019 18:47
simple node http server responding after 10 seconds for every endpoing
const http = require('http');
const url = require('url');
const port = 4569;
const requestHandler = (request, response) => {
console.log("received request");
setTimeout(function() {
response.end("yo");
}, 10000);
}
@raj454raj
raj454raj / floatsign.sh
Created October 6, 2017 06:59 — forked from mediabounds/floatsign.sh
A small bash script to re-sign iOS applications.
# !/bin/bash
# Copyright (c) 2011 Float Mobile Learning
# http://www.floatlearning.com/
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
@raj454raj
raj454raj / setup.sh
Created May 30, 2017 18:40
Web2py nginx deployment in Ubuntu
#!/bin/bash
echo 'setup-web2py-nginx-uwsgi-ubuntu-precise.sh'
echo 'Requires Ubuntu > 12.04 or Debian >= 8 and installs Nginx + uWSGI + Web2py'
# Check if user has root privileges
if [[ $EUID -ne 0 ]]; then
echo "You must run the script as root or using sudo"
exit 1
fi
# parse command line arguments
nopassword=0
<!-- File: layout.html -->
<!DOCTYPE html>
<html>
<body>
<h1>Hello {{ name }}!</h1>
<h1>Age {{ age }}!</h1>
{% for i in range(5) %}
<h2> {{ i }} </h2>
{% endfor %}
</body>
from flask import *
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
from flask import *
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
from bs4 import BeautifulSoup
session = requests.Session()
response = session.get("http://lightoj.com/login_main.php")
print response
cookies = session.cookies.get_dict()
response = session.post("http://lightoj.com/login_check.php",
data={"myuserid": "hsharma@maileme101.com",
"mypassword": "admin123",
"Submit": "Login"},