Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jitendra adhocore

🎯
Focusing
View GitHub Profile
@adhocore
adhocore / git-branch.md
Created May 15, 2019
Get current git branch without using `git` command
View git-branch.md
cat .git/HEAD | cut -c17-9999

Useful if you are in docker and dont want to install git in your container :)

@adhocore
adhocore / maqebot.php
Last active Oct 8, 2017
Maqe Bot (PHP7). Sample usage: `php maqebot.php W5RW5RW2RW1R`
View maqebot.php
<?php
/**
* The Bot.
*/
class Bot
{
const DIR_NORTH = 0;
const DIR_EAST = 1;
const DIR_SOUTH = 2;
@adhocore
adhocore / qwerty.php
Created Dec 13, 2015
map English alphabets to their position in qwerty layout keyboard, and reverse
View qwerty.php
<?php
/*
* QWERTY encode decode
*
* qwerty_encode maps English alphabets to their
* position in qwerty layout keyboard like so:
* a -> q, b -> w, c -> e ... etc
*
* qwerty_decode does the reverse
@adhocore
adhocore / upload.php
Last active Feb 4, 2017
AJAX file upload with progress bar, as minimal as it can be.
View upload.php
<?php
/*
* AJAX file upload with progress bar, as minimal as it can be.
* If it doesnot work try latest version of web browser.
*/
// big file upload
ini_set('memory_limit', '1G');
@adhocore
adhocore / sub.php
Last active Sep 9, 2015
A simple php cli tool to traverse movie directories and download the missing subtitles from subscene.com (suited for movies from yify torrents)
View sub.php
#!/usr/bin/env php
<?php
/*
* A simple php cli tool to traverse movie directories
* and download the missing subtitles from subscene.com
* (Especially suited for movies from yify torrents)
*
* Usage: php sub.php /path/to/movies/
*
View primes.php
<?php
/**
* Alternative prime number generator
*
* Generates first <n> prime numbers using
* the prime numbers themselves
*
* @author Jitendra Adhikari <jiten.adhikary@gmail.com>
*
@adhocore
adhocore / expand_array.php
Last active Dec 19, 2019
A helper function expand_array for PHP
View expand_array.php
<?php
/**
* A helper function expand_array for PHP
*
* This is actually developed during the real need to develop JSON api
* I wanted to have JSON api response spitted properly expanded (with semantic nodes)
* But didnot want to do it by playing with arrays (looping, merging n' what not) time and again.
* So, After fetching single dimensional array data from database, with keys having
* some specific delimeter, this helper would do for me what i want to.
@adhocore
adhocore / str_ireplace_array.php
Last active May 7, 2020
A str_replace_array for PHP
View str_ireplace_array.php
<?php
/**
* A str_ireplace_array for PHP
*
* Case insensitive version of str_replace_array
* See https://wiki.php.net/rfc/cyclic-replace
*
* @author Jitendra Adhikari | adhocore <jiten.adhikary@gmail.com>
*
@adhocore
adhocore / Obfuscator.php
Created Dec 31, 2013
Obfuscator - The naive and trivial PHP Code obfuscator | deobfuscator
View Obfuscator.php
<?php
/**
* Obfuscator - The naive and trivial PHP Code obfuscator | deobfuscator
*
* generate() Generates a obfuscated string of given code
* also gives the chunk value required by work()
* work() Reverses the obfuscated string using chunk value given by generate()
* to original code and then execute the code and returns response
*
@adhocore
adhocore / stringBorder.php
Created Dec 18, 2013
max length of border having atleast three non-overlapping occurance in a string
View stringBorder.php
<?php
/**
* For a given string S, a substring b is said to be its border if S starts and end with b.
* Suppose we need length of longest border b that also occurs in S, even after b is trimmed at ends of S.
*
* This function is aimed at that need. ;)
*
*/
function maxBorderLen($S){