Skip to content

Instantly share code, notes, and snippets.

View jabranr's full-sized avatar
🚀
Building ideas

Jabran Rafique jabranr

🚀
Building ideas
View GitHub Profile
@jabranr
jabranr / loop.js
Last active September 17, 2017 09:04
(Math) Generate a loop with maximum range
// Increase until a range is met then start again:
let range = 10;
let x = (x + 1) % range;
@jabranr
jabranr / Cache.js
Last active January 5, 2017 17:43
[JavaScript] Cache data in memory
/**
* This snippet is now a small library!
* @link https://github.com/jabranr/js-memcache
*/
@jabranr
jabranr / .gitignore_global
Last active September 19, 2018 18:05
Global gitignore (see default gitconfig - https://gist.github.com/jabranr/504922fe20fe0ff2bafa)
.rsync_cache
.vagrant
*~
Guardfile
*.swp
.idea
.DS_Store?
.DS_Store
ehthumbs.db
Icon?
@jabranr
jabranr / toggle-multiple-buttons-with-different-text.js
Last active September 5, 2016 11:58
[jQuery] Toggle multiple buttons at same with different text
$.fn.extend({
disableCta: function() {
this.prop('disabled', true);
// or use your own class
this.addClass('btn--disabled');
// retain current text of the CTA in custom data attribute
// Used html() assuming it is a <button> element
this.attr('data-value', this.html());
@jabranr
jabranr / BaseEntity.php
Last active July 25, 2016 16:10
[POC DRY] BaseEntity class to be used as base for Entities in Symfony2.
<?php
namespace Foo\Bar\Entity;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping as ORM;
/**
* BaseEntity
*
@jabranr
jabranr / prepare-commit-msg.sh
Last active June 20, 2016 12:47
PUT a JIRA ticket numebr into commit message
# Save in .git/hooks/prepare-commit-msg
#
# This means that current branch was branched
# out from JIRA/Bitbucket and has a JIRA
# ticket number in its name.
JIRA=$(cat .git/HEAD | grep -Eo "[A-Z]+-[0-9]+")
echo "$JIRA" >> "$1"
@jabranr
jabranr / sublime_custom_getter_setter.py
Last active June 19, 2016 09:09
Sublime custom template for PHP Getters and Setters package
# Save the file to "{Sublime Packages}/PHP Getters and Setters/user_templates.py"
# Then add following "user config" in Sublime Text:
#
# {
# "registerTemplates" : [ "customTemplate" ],
# "template" : "customTemplate"
# }
#
# Restart Sublime Text
#
@jabranr
jabranr / .editorconfig
Created April 26, 2016 08:09
Editor config
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
@jabranr
jabranr / mysql_backup_cron.sh
Last active June 6, 2021 14:05
Automatic MySQL dump and backup to Git repo cron job
#!/bin/sh
#
# @author: Jabran Rafique <hello@jabran.me>
# @link: http://jabran.me/articles/automatic-database-backup-using-git-hosting/
# Set variables
FULLDATE = $(date +"%Y-%d-%m %H:%M")
NOW = $(date +"%Y-%m-%d-%H-%M")
MYSQL_DUMP = `which mysqldump`
GIT = `which git`
@jabranr
jabranr / php-get-set.sublime-snippet
Created April 1, 2016 14:47
Autogenerate PHP getters setters
<snippet>
<content><![CDATA[
/**
* Get ${1/(.*)/\u$1/:[ Prop name ]}
* ${4:[description]}
*
* @return ${3:[type]}
*/
public function get${1/(.*)/\u$1/:[ Prop name ]}() {
return \$this->${1:[ Prop name ]};