Skip to content

Instantly share code, notes, and snippets.

View masihyeganeh's full-sized avatar

Masih Yeganeh masihyeganeh

View GitHub Profile

KSQL Stuffs

To Aggregate watchtime

Aparat

CREATE STREAM APARAT_WATCH (ip VARCHAR, req_ip VARCHAR, vid BIGINT, uid VARCHAR, userid BIGINT, afcn VARCHAR, session_id VARCHAR, profile VARCHAR, watch DOUBLE, progress DOUBLE, position BIGINT, duration VARCHAR, timestamp BIGINT, payload_time BIGINT, chunkname VARCHAR, download INTEGER, watch_type VARCHAR) WITH (kafka_topic='aparat_watch', value_format='JSON', timestamp='timestamp');
@masihyeganeh
masihyeganeh / banks.json
Created September 20, 2018 21:55
Map of SHEBA and card number to bank name
{
"sheba": {
"55": "اقتصاد نوین",
"63": "انصار",
"69": "ایران زمین",
"54": "پارسیان",
"57": "پاسارگاد",
"21": "پست بانک",
"62": "آینده",
"18": "تجارت",
@masihyeganeh
masihyeganeh / README.md
Created February 9, 2017 12:30
Improved Retrofit Call

I just didn't like the way Retrofit is calling methods and I wanted to improve it. I believe error handling can be done much nicer. Here is what I did.

Preparing web service object to call remote methods:

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("http://example.com/web-api/v1/")
        .addConverterFactory(GsonConverterFactory.create())
        .build();
@masihyeganeh
masihyeganeh / reader.php
Created March 14, 2014 16:32
Weird PHP session lock
<?php
set_time_limit(0);
session_start();
print $_SESSION['something'];
@masihyeganeh
masihyeganeh / gist:7527325
Last active December 28, 2015 16:09
Generating Self-signed Certificate
mkdir keys # All keys will be generated in this folder
openssl genrsa -out keys/rootCA.key 2048 -des3 # CA Private key
openssl req -x509 -new -nodes -key keys/rootCA.key -days 1024 -out keys/rootCA.pem # CA self-signed certificate valid for 1024 days
# CA certificate should be imported to all devices that are using these self-signed certificates
openssl genrsa -out keys/server.key 2048 # Server private key
openssl req -new -key keys/server.key -out keys/server.csr # Server certificate signing request
openssl x509 -req -in keys/server.csr -CA keys/rootCA.pem -CAkey keys/rootCA.key -CAcreateserial -out keys/server.crt -days 1024 # Common Name should be server's host name or ip
@masihyeganeh
masihyeganeh / gist:7513237
Created November 17, 2013 13:11
Leading zero is valuable in PHP, hmmm... somtimes
<?php
// This will always make a writable folder with "0755" permission
mkdir('/some/path', 0777);
// But this won't! this will make folder with "1352" permission
mkdir('/some/path', 777);
@masihyeganeh
masihyeganeh / SoundCloud-Links
Created July 15, 2013 11:11
Prints download link of all tracks of a SoundCloud user. copy and paste it in URL bar in user's page
@masihyeganeh
masihyeganeh / gist:4156943
Last active October 13, 2015 06:58
Snippet to get Only derived class's methods list
<?php
/**
* Gets public methods name of a class only defined in that class,
* not it's parent
*
* @param string $className Name of the class.
*
* @return array Returns list of methods.
*/
@masihyeganeh
masihyeganeh / gist:3363139
Created August 15, 2012 20:02
Template of an Object Oriented node.js module
var Class = (function Class() {
var singleton_private_variable = 'Singleton Private variable';
function singleton_private_function () {
return 'Private Function';
}
var Obj = {
singleton_public_variable: 'Singleton Public variable',
@masihyeganeh
masihyeganeh / Google_PageRank_Checker.php
Created July 13, 2012 11:50
Gets Google pagerank of a website
<?php
define("GOOGLE_MAGIC", 0xE6359A60);
function zeroFill($a, $b)
{
$z = hexdec(80000000);
if ($z & $a) {
$a = ($a >> 1);
$a &= (~$z);