Skip to content

Instantly share code, notes, and snippets.

View akhal3d96's full-sized avatar

Ahmed Khaled akhal3d96

View GitHub Profile
# pool_size: number of threads
# jobs: A queue (See: https://rubyapi.org/3.0/o/queue)
def thread_pool(pool_size: 4, jobs:, &block)
threads = []
results = []
mutex = Mutex.new
pool_size.times do
threads << Thread.new do
while !jobs.empty? do
@akhal3d96
akhal3d96 / jenkins-docker-did.yml
Created October 4, 2021 12:12
Jenkins with Docker In Docker
version: "3.9"
services:
jenkins-docker:
image: docker:dind
privileged: true
volumes:
- jenkins-docker-certs:/certs/client
- jenkins_home:/var/jenkins_home
@akhal3d96
akhal3d96 / .prettier.json
Created February 2, 2021 13:23
My prettier configuration
{
"singleQuote": true,
"semi": false,
"trailingComma": "none"
}
@akhal3d96
akhal3d96 / shuffle.js
Created August 15, 2020 16:44
Shuffle a Javascript Array
/**
* Randomize the order of the elements in a given array.
* source: https://github.com/pazguille/shuffle-array/blob/master/dist/shuffle-array.js
* @param {Array} arr - The given array.
* @returns {Array}
*/
export function shuffle (arr) {
if (!Array.isArray(arr)) {
throw new Error('shuffle expect an array as parameter.')
}
@akhal3d96
akhal3d96 / pipe.js
Last active August 8, 2020 15:22
pipe(fn1, fn2, f3)(data) == fn1(fn2(fn3(data)))
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x)
ls -a |\
grep -E "^\.(.)+~$" |\
xargs -I {} ls -l {} |\
awk {'print $5'} |\
paste -sd+ |\
bc
@akhal3d96
akhal3d96 / caitw.sh
Last active January 19, 2017 22:20
A simple script to convert the grabage you collect through the internet (aka memes) and other unimportant images you have to lossy webp image which will save you some space. Past it into a directory and it will compress anything in it. It's very destructive use it wisely.
#!/usr/bin/bash
BSIZE=$(du -Ss $PWD | awk '{print $1}')
function finish(){
ASIZE=$(du -Ss $PWD | awk '{print $1}')
FSIZE=$((BSIZE-ASIZE))
echo $(python -c "print($FSIZE/1000.0)")MB
}
trap finish EXIT
find $PWD -maxdepth 1 -size -1024k -iname "*.jpg" -or -iname "*.png" | xargs -I '{}' sh -c '(echo converting "{}" && cwebp "{}" -mt -q 80 -o "{}".webp 2> /dev/null || true) && rm "{}"'
#Remove -maxdepth 1 to make it recursive (NOT RECOMMENDED)
@akhal3d96
akhal3d96 / start_vpn.sh
Last active August 22, 2016 13:05
Quickly establish a connection with a free VPN server in USA in order to access Spotify's services
curl -o vpn.zip -s "https://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-US1.zip" && unzip vpn.zip -d ~/vpn_files && echo "vpnbook" > ~/.auth && curl -s "https://www.vpnbook.com/" | grep Password | tr -d '\t\n\r\f' | grep -Eo 'Password: [a-zA-Z0-9]*' | uniq | sed 's/Password: //' >> ~/.auth && sudo openvpn --config ~/vpn_files/vpnbook-us1-tcp443.ovpn --auth-user-pass ~/.auth
[Trigger]
Type = File
Operation = Upgrade
Target = *
[Action]
When = PostTransaction
Exec = /etc/pacman.d/hooks/ruby-gems-update.sh
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1000001
int main()
{
int size,i,x,most=-1,mostn,times[MAX],start[MAX],end[MAX];