Skip to content

Instantly share code, notes, and snippets.

View masihyeganeh's full-sized avatar

Masih Yeganeh masihyeganeh

View GitHub Profile
@masihyeganeh
masihyeganeh / ConvertFinglishToFarsi.class.php
Created March 7, 2012 09:48
Finglish to Persian transliteration
<?php
@error_reporting(E_ALL);
@set_time_limit(0);
class ConvertFinglishToFarsi
{
/**
* Default Options
*/
public $useFarsiNumbers = false; //Replace English numbers with Persian numbers
@masihyeganeh
masihyeganeh / SelectCourse.php
Created July 8, 2012 11:10
Functions to login to University website and select cources
<?php
function LoginAndGetCookie($server='82.99.229.141', $user, $pass)
{
$status = 'Error';
$data = 'مشکلی در انجام عملیات بوجود آمد. شاید به دلیل شلوغی سایت، این مشکل بوجود آمده. لطفاً بعداً دوباره امتحان کنید';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://' . $server . '/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0');
@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);
@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 / 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 / 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: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 / 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 / reader.php
Created March 14, 2014 16:32
Weird PHP session lock
<?php
set_time_limit(0);
session_start();
print $_SESSION['something'];
@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();