Skip to content

Instantly share code, notes, and snippets.

View scheler's full-sized avatar

Santosh Cheler scheler

  • Santa Clara, CA
View GitHub Profile
@scheler
scheler / gist:26a942d34fb5576a68c111b05ac3fabe
Created July 23, 2020 00:17
String hash function in Lua
function hash(str)
h = 5381;
for c in str:gmatch"." do
h = ((h << 5) + h) + string.byte(c)
end
return h
end
@scheler
scheler / gist:59b94918931de5473b1c353345bfd6c4
Created June 23, 2020 17:48
Simultaneous and parameterized curl requests using GNU Parallel
parallel --jobs 2 curl -O -s http://example.com/?page{}.html ::: {1..10}
# source: https://stackoverflow.com/questions/8634109/parallel-download-using-curl-command-line-utility
@scheler
scheler / gist:19fa9cd307b3d293ffc2e8660937392f
Last active August 21, 2019 17:04
Distinguishing curl client and server errors
function curl_client_error() {
if [ "$2" == "4" ]; then
echo $1: Error resolving proxy
elif [ "$2" == "6" ]; then
echo $1: Error resolving host
elif [ "$2" == "7" ]; then
echo $1: Error connecting to host
elif [ "$2" == "28" ]; then
echo $1: Server response timed out.
fi
@scheler
scheler / gist:b2fd24c10652b8ec3cb5a0faa5c38e46
Last active July 22, 2018 00:37
hazelcast map listener example python
import hazelcast, logging
config = hazelcast.ClientConfig()
# Hazelcast.Address is the hostname or IP address, e.g. 'localhost:5701'
config.network_config.addresses.append('localhost5701')
# basic logging setup to see client logs
logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)
@scheler
scheler / rotateArray.py
Last active July 22, 2018 00:36
Rotate right a 2d array by 90 degrees using constant space usage
def rotateSquare(a, start, length):
lastIndex = start + length - 1
for i in range(length-1):
temp = a[start][start + i]
a[start][start + i] = a[lastIndex - i][start]
a[lastIndex - i][start] = a[lastIndex][lastIndex - i]
a[lastIndex][lastIndex - i] = a[start + i][lastIndex]
a[start + i][lastIndex] = temp