Skip to content

Instantly share code, notes, and snippets.

@satiridev
satiridev / starman.hs
Last active September 30, 2016 22:14
starman example from futururelearn.com
-- main function
starman :: String -> Int -> IO ()
starman word n = turn word ['-' | x <- word] n
--
check :: String -> String -> Char -> (Bool, String)
check word display c = (c `elem` word,
[if x == c then c
else y |
(x,y) <- zip word display])
@satiridev
satiridev / checkPostContent.php
Created October 17, 2017 08:45
Check the number of post content in wordpress multiplesite
<?php
/**
* count all blog posts
* blog which has most content will be suspect breach
*/
$link = mysqli_connect("127.0.0.1", "dbuser", "dbpass", "dbname");
if (!$link) {
echo "Connection failed \n";
@satiridev
satiridev / cmd.sh
Created August 16, 2019 06:56 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
# get system fonts
import matplotlib.font_manager
matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
@satiridev
satiridev / createimage.py
Last active August 19, 2019 03:28
create written image using truetype font in python
# from https://code-maven.com/create-images-with-python-pil-pillow
from PIL import Image, ImageDraw, ImageFont
# mode L for grayscale
img = Image.new('RGB', (100, 30), color = (73, 109, 137))
# font path
fnt = ImageFont.truetype('/Library/Fonts/Arial.ttf', 15)
d = ImageDraw.Draw(img)
d.text((10,10), "Hello world", font=fnt, fill=(255, 255, 0))
@satiridev
satiridev / collect-files-in-s3-bucket.sh
Last active November 6, 2020 03:27
Collect All Files in A AWS S3 Bucket
#!/bin/bash
# produce list of all files in buckets
echo "collecting..."
aws s3 ls --recursive my-bucket > my-files-in-bucket.txt
@satiridev
satiridev / delete-files-in-bucket.sh
Created November 6, 2020 03:26
delete list of files from AWS S3 bucket list result
#!/bin/bash
cat my-target-files-in-s3.txt | awk '{print $4}' | while read x; do aws s3 rm "s3://my-bucket-name/$x"; done > my-delete-result.txt
#!/bin/bash
# git
alias gp='git pull '
alias gpo='git push origin '
alias gs='git status '
alias gsl='git stash list '
alias gss='git stash save '
alias gcm='git commit -m '
alias ga='git add '
#!/bin/bash
# -F',' will split by comma
# BEGIN{RS="\r\n"} will remove \r\n (crlf) from the end of the string
# {print $3} will take the 3rd column and pass it to the next command
# -G option will read the data-urlencode
cat some.csv | awk -F',' 'BEGIN{RS="\r\n"}{print $3}' | while read x; do curl -v -G --data-urlencode "email=$x" \
-X POST "https://path/to/the/host" \
-H "accept: */*" \
-H "Authorization: Bearer some-jwt-string-for-authorization"; done
#!/bin/bash
# tested in .zshrc
#
# kubectl scale deploy name-of-deployment --replicas=0
# kubectl scale deploy name-of-deployment --replicas=1
alias kscale="kubectl scale deploy "
function krestart(){
for i in {0..1};