Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
waleedsamy / subquery-performance.sql
Last active August 29, 2015 14:15
MySql subquery performance enhancment
-- enviroment : Mysql 5.5
-- worst peerformance frist
--explain query indicate it not depend on any index on partent query ( so it will full scan on table with 11M )
SELECT co_id FROM argo.v_r_p_master WHERE mn_code
IN (
SELECT pk_data FROM argo.s_r_d_l WHERE insert_date > (NOW() - INTERVAL 1 DAY)
AND table_name IN ('argo.mn_code') AND pk_data IS NOT NULL
);
@waleedsamy
waleedsamy / chlorum2014.py
Last active August 29, 2015 14:17
codaility chlorum2014 challenge
# https://codility.com/programmers/custom_challenge/chlorum2014
# not pass yet
# SAMPLE DATA
# C=[1, 3, 0, 3, 2, 4, 4]
# D=[6, 2, 7, 5, 6, 5, 2]
# K=5
C=[1,3,0,3,2,4,4]
D=[6,2,7,5,6,5,2]
K=2
@waleedsamy
waleedsamy / virtual.cpp
Created April 27, 2015 08:39
c++ opp , virtual keyword
// virtual is all about binding , early binding in compliation so it will determine abject and so method to call
// as reference is or late binding shen method is virtual so binding determine in run time dynamically
// according to actual type of object and sall it's method
// depend on http://stackoverflow.com/questions/2391679/why-do-we-need-virtual-methods-in-c
#include <iostream>
using namespace std;
class Animal
{
@waleedsamy
waleedsamy / sri.bash
Created September 21, 2015 07:59
Subresource Integrity - SRI
## http://www.w3.org/TR/SRI
## modern browser chrome 45+ or firefix 43+ will check hash of javascript or css resource
## aginst new attribute 'integrity' and if not matched browser will not load this resources
alg=sha256
resource=resource.css;
integrity=$(cat $resource | openssl dgst -$alg -binary | openssl enc -base64 -A)
printf '<link rel="stylesheet" href="resource.css" integrity="%s%s">\n' "$alg-$integrity"
This file has been truncated, but you can view the full file.
{"sku-1":{"att-a":"att-a-7","att-b":"att-b-3","att-c":"att-c-10","att-d":"att-d-10","att-e":"att-e-15","att-f":"att-f-11","att-g":"att-g-2","att-h":"att-h-7","att-i":"att-i-5","att-j":"att-j-14"},"sku-2":{"att-a":"att-a-9","att-b":"att-b-7","att-c":"att-c-12","att-d":"att-d-4","att-e":"att-e-10","att-f":"att-f-4","att-g":"att-g-13","att-h":"att-h-4","att-i":"att-i-1","att-j":"att-j-13"},"sku-3":{"att-a":"att-a-10","att-b":"att-b-6","att-c":"att-c-1","att-d":"att-d-1","att-e":"att-e-13","att-f":"att-f-12","att-g":"att-g-9","att-h":"att-h-6","att-i":"att-i-7","att-j":"att-j-4"},"sku-4":{"att-a":"att-a-9","att-b":"att-b-14","att-c":"att-c-7","att-d":"att-d-4","att-e":"att-e-8","att-f":"att-f-7","att-g":"att-g-14","att-h":"att-h-9","att-i":"att-i-13","att-j":"att-j-3"},"sku-5":{"att-a":"att-a-8","att-b":"att-b-7","att-c":"att-c-10","att-d":"att-d-4","att-e":"att-e-11","att-f":"att-f-4","att-g":"att-g-8","att-h":"att-h-8","att-i":"att-i-7","att-j":"att-j-8"},"sku-6":{"att-a":"att-a-6","att-b":"att-b-2","att-c":"at
@waleedsamy
waleedsamy / instructions.md
Last active October 3, 2015 18:21
search for match between objects

Input Data Given json contains 20K articles. Each article contains set of attributes with one set value.

Recommendation Engine Requirements Calculate similarity of articles identified by sku based on their attributes values. Attributes with name higher in alphabet (a is higher than z) is weighted with heavier weight.

Absolute weighting values are up to engineer. Relative order as described above should be maintained.

@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 / 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