Skip to content

Instantly share code, notes, and snippets.

View fazlurr's full-sized avatar

Fazlur Rahman fazlurr

View GitHub Profile
@fazlurr
fazlurr / printProperty.js
Created April 2, 2014 11:18
Javascript function to show all object property
for (var key in items.images) {
var obj = items.images[key];
for (var prop in obj) {
if(obj.hasOwnProperty(prop)){
console.log(prop + " = " + obj[prop]);
}
}
}
@fazlurr
fazlurr / hexToRgb.js
Created April 7, 2014 03:51
RGB to Hex and Hex to RGB conversion with Javascript, From : http://stackoverflow.com/a/5624139
function hexToRgb(hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
@fazlurr
fazlurr / showPopupOnClose.js
Created April 23, 2014 10:42
jQuery function to show popup on window close
$(window).bind("beforeunload", function() {
return confirm("Do you really want to close?");
});
@fazlurr
fazlurr / imagePreview.js
Created April 28, 2014 04:33
jQuery function for showing preview on image upload
function preview(input) {
var theID = $(input).attr('data-id');
console.log(theID);
var imgPreview = $('.preview[data-id='+theID+']');
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
imgPreview.attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
@fazlurr
fazlurr / wpRedirect.php
Created April 29, 2014 12:23
WP redirect
<?php
if (isset($_POST))
{
$error_found = FALSE;
// Some input field checking
if ($error_found == FALSE)
{
// Use the wp redirect function
<?php
if(qtrans_getLanguage()=='en') {
// put your code here if the current language code is 'en' (English)
} elseif(qtrans_getLanguage()=='id') {
// put your code here if the current language code is 'id' (Indonesian)
}
?>
@fazlurr
fazlurr / button.xml
Last active August 29, 2015 14:01
Android Ok and Cancel flat button with divider (from Android Design in Action)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true">
<View
/* CSS Hacks from http://www.quora.com/Web-Development/What-are-the-most-interesting-HTML-JS-DOM-CSS-hacks-that-most-web-developers-dont-know-about
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
/**
* Gradient Background from http://aerotwist.com/static/design/better-password-form-fields/demo/index.html
*/
background: #f06;
background-image: radial-gradient(circle farthest-side at 66% -9%, #FFFFFF 0%, #FAE7D3 6%, #93CDC4 25%, #2B73A4 61%, #003D62 87%, #010A37 100%);
min-height: 100%;
function opposite(c) {
var result='';
var ch='';
var list1='0123456789ABCDEF';
var list2='FEDCBA9876543210';
for (var i=0; i<c.length; i++) {
ch=c.charAt(i);
for (var n=0; n<list1.length; n++) {
if(ch==list1.charAt(n)) result += list2.charAt(n);