Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
waleedsamy / .jshintrc
Created October 7, 2015 15:15
recommended jshint config file
{
"maxerr": 10,
"curly": true,
"boss": true,
"expr": true,
"node": true,
"onevar": true,
"white": true,
"eqeqeq": true,
"latedef": true,
@waleedsamy
waleedsamy / .jsbeautifyrc.js
Created October 7, 2015 15:16
recommended js-beautify config file
{
indent_size: 4,
indent_char: " ",
eol: " ",
indent_level: 0,
indent_with_tabs: false,
preserve_newlines: true,
max_preserve_newlines: 10,
jslint_happy: false,
space_after_anon_function: false,
@waleedsamy
waleedsamy / git_valid_email.sh
Created October 11, 2015 16:16
git pre-commit hook to restrict and validate author email
#!/usr/bin/bash
# This pre-commit hook will prevent any commit by unvalid author email
# or restricted email/s regex
restrict_regex=$i
email="$(git config user.email)"
if [[ "$email" =~ "^[A-Za-z0-9._%+-]+<b>@</b>[A-Za-z0-9.-]+<b>\.</b>[A-Za-z]{2,4}$" ]]
@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 / createZendeskTicket.js
Last active November 17, 2015 08:53
post data with request.js
var request = require("request");
/**
curl https://{subdomain}.zendesk.com/api/v2/tickets.json \
-d '{"ticket": {"subject": "My printer is on fire!", "comment": { "body": "The smoke is very colorful." }}}' \
-H "Content-Type: application/json" -v -u {email_address}:{password} -X POST
*/
var options = {
url: "https://{subdomain}.zendesk.com/api/v2/tickets.json",
method: "POST",
@waleedsamy
waleedsamy / testing.md
Last active November 29, 2015 15:54
testing, content collected from web

“I don’t have time to write tests because I am too busy debugging.”

Why

  • T E S T S A R E G O O D D O C U M E N TAT I O N
  • TESTS REDUCE BUGS
  • TESTING FORCES YOU TO THINK
  • TESTS REDUCE FEAR

The goal of unit testing is:

  1. to isolate each part of the program, and
@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 / 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 \