Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
waleedsamy / largePrime.c
Created December 14, 2015 14:26
A small C program to print the biggest prime number
/* source: http://bellard.org/mersenne.html */
int m=1711276033,N=1,t[1<<25]={2},a,*p,i,e=39717691,s,c,U=1;g(d,h){for(i=s;i<1<<
24;i*=2)d=d*1LL*d%m;for(p=t;p<t+N;p+=s)for(i=s,c=1;i;i--)a=p[s]*(h?c:1LL)%m,p[s]
=(m*1U+*p-a)*(h?1LL:c)%m,*p=(a*1U+*p)%m,p++,c=c*1LL*d%m;}main(){while(e/=2){N*=2
;U=U*1LL*(m+1)/2%m;for(s=N;s/=2;)g(40,0);for(p=t;p<t+N;p++)*p=*p*1LL**p%m*U%m;
for(s=1;s<N;s*=2)g(983983719,1);for(a=0,p=t;p<t+N;)a+=*p<<(e&1),*p++=a%10,a/=10;
}while(!*--p);for(t[0]--;p>=t;)putchar(48+*p--);}
@waleedsamy
waleedsamy / ssh.md
Last active December 16, 2015 13:45
use ssh for baby

ssh generate public and private key

  • anyone can has your public key but only you can has private key
  • anyone nat send you secure message will encrypt it with your public key
  • who has private key able to see message content after decoding it with private key

To be able to connect to server with ssh without asking you credentials

  • add your public key to ~/.ssh/authorized_keys as here
@waleedsamy
waleedsamy / docker-cluster.md
Last active December 20, 2015 13:17
docker cluster
docker --version
# Docker version 1.9.1, build a34a1d5
docker-machine --version
# docker-machine version 0.5.4, build 6643d0e

docker run swarm create
# $TOKEN
docker-machine create \
 -d virtualbox \
@waleedsamy
waleedsamy / ffmd.sh
Created December 27, 2015 10:13
find first matched directory
# can pass any find param
# ~/ffmd.sh . -maxdepth 2 -type d -name "you-should-*"
find $@ -print -quit
@waleedsamy
waleedsamy / sardc.sh
Last active December 27, 2015 13:37
stop and remove docker container
#
### cnt=$(docker ps -a | awk 'NR>1 {print $1}') && docker stop $cnt && docker rm $cnt
### docker stop $cnt && docker rm $cnt
#
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)
@waleedsamy
waleedsamy / jsonenv.py
Last active December 27, 2015 15:29
inflate JSON object to environment variable like `a=b`
#!/usr/bin/env python
import os, json
import sys, getopt
#stolen from https://medium.com/@amirziai/flattening-json-objects-in-python-f5343c794b10#.q8cod4ei7
def flatten_json(y):
out = {}
def flatten(x, name=''):
if type(x) is dict:
@waleedsamy
waleedsamy / tflf.sh
Created January 4, 2016 09:42
tail forever log files
tail -f $(nvm use 0.12 | forever list | awk 'NR>2 {print $8}')
@waleedsamy
waleedsamy / dl_sc_fav_tracks.md
Last active January 18, 2016 08:07
download my best tracks @Midnigh then send me an email

download my best tracks @midnigh then send me an email

at -m midnight
>> echo "EOE" | mail -s "scdl start !" waleedsamy634@gmail.com && \
   scdl -c -l https://soundcloud.com/rana-abdel-ghafar/sets/uuyoj2yj1obw && \
   echo "EOE" | mail -s "scdl done !" waleedsamy634@gmail.com
>> <EOT>

install sendmail

@waleedsamy
waleedsamy / regit.sh
Last active February 17, 2016 14:15
git fresh version of a branch
###
## install: curl https://gist.githubusercontent.com/waleedsamy/921294a0e5bdd49cf4c4/raw/e3ccf5123f49cd70af542e6de077995f9b040f4b/regit.sh > ~/regit.sh && chmod +x ~/regit.sh
## usage: ~/regit.sh master
###
regit(){
if [ $# -eq 1 ]
then
project=${PWD}
brnch=$1
tmp="$RANDOM-tmp"
@waleedsamy
waleedsamy / hello-centos-7-repos.sh
Last active March 25, 2016 20:40
thirdparty yum repos
###
## usage: curl https://gist.githubusercontent.com/waleedsamy/313bd0625c50724080ff/raw/c1c35c4ce5babd2a89d94363bbc2c289e0f81ccb/hello-centos-7-repos.sh > ~/hello-centos-7-repos.sh && chmod +x ~/hello-centos-7-repos.sh && ~/hello-centos-7-repos.sh
###
echo "[tor]
name=Tor repo
enabled=1
baseurl=https://deb.torproject.org/torproject.org/rpm/el/7/x86_64/
gpgcheck=1
gpgkey=https://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org.asc
repo_gpgcheck=1