Skip to content

Instantly share code, notes, and snippets.

@jamalnasir
jamalnasir / last_commit.sh
Created September 11, 2017 08:04
Zipped all files in last commit.
#!/usr/bin/env bash
# checks if branch has something pending
function files() {
hashid=$(parse_git_hash)
hashid=${hashid#@}
git diff-tree --no-commit-id --name-only -r $hashid
}
@jamalnasir
jamalnasir / rubymine.txt
Created April 5, 2017 12:24
Rubymine Activation
Version: 2016.3.2
Select License server and paste the following
http://idea.imsxm.com/
@jamalnasir
jamalnasir / digits_range.php
Last active April 29, 2018 07:16
Leading zero digits range in PHP
<?php
public function getLeadingZeros($begin, $end){
$range = [];
foreach(range($begin, $end) as $key=>$value){
$digit = str_pad($value, 2, "0", STR_PAD_LEFT);
$range[$digit] = $digit;
}
return $range;
}
@jamalnasir
jamalnasir / git.txt
Last active July 29, 2021 09:14
Git Commands
git commit [some files]
Or if you are sure that you have a clean staging area you can
git add [some files] # add [some files] to staging area
git add [some more files] # add [some more files] to staging area
git commit # commit [some files] and [some more files]
git commit file1 file2 file5 -m "commit message"
If you want to make that commit available on both branches you do
git stash # remove all changes from HEAD and save them somewhere else
@jamalnasir
jamalnasir / mouse_up_down.js
Created March 23, 2017 14:14
Mouse Wheel Up and Down Detection in JS
//Firefox
jQuery('#wrapper').bind('DOMMouseScroll', function(e){
if(e.originalEvent.detail > 0) {
//scroll down
console.log('Down');
}else {
//scroll up
console.log('Up');
}
@jamalnasir
jamalnasir / regex.txt
Created March 20, 2017 07:25
Regular expressions for different attributes
Email regex
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
@jamalnasir
jamalnasir / add_minutes.js
Created March 19, 2017 13:13
Adding minutes to time
function addMinutes(time, minsToAdd) {
function z(n){
return (n<10? '0':'') + n;
}
var bits = time.split(':');
var mins = bits[0]*60 + (+bits[1]) + (+minsToAdd);
return z(mins%(24*60)/60 | 0) + ':' + z(mins%60);
}
@jamalnasir
jamalnasir / set_csrf.txt
Last active March 13, 2017 15:21
Setting csrf token for every ajax call
<!doctype html>
<html>
<head>
<title>Manage Contact Types</title>
<link rel="stylesheet" href="....">
<meta name="csrf-token" content="<?php echo csrf_token() ?>"/>
</head>
$(function () {
@jamalnasir
jamalnasir / read_image.js
Last active March 7, 2018 11:03
Javascript Snippet to Read an Image Object
$('#file-input').change(function(e){
var files = e.target.files;
for (var i = 0, f; f = files[i]; i++) {
if(f.type){
var image_types = ['image/png', 'image/jpg', 'image/jpeg'];
if((f.type && image_types.indexOf(f.type) < 0)) {
alert('Invalid file selected. Supported formats are jpeg and png.');
$(this).val('');
} else {
readURL(f, $('.image-preview'));
@jamalnasir
jamalnasir / strftime_date_formats.txt
Created March 13, 2017 01:36
strftime date formats
%a - abbreviated weekday name
%A - full weekday name
%b - abbreviated month name
%B - full month name
%c - preferred date and time representation
%C - century number (the year divided by 100, range 00 to 99)
%d - day of the month (01 to 31)
%D - same as %m/%d/%y
%e - day of the month (1 to 31)
%g - like %G, but without the century