Skip to content

Instantly share code, notes, and snippets.

View abdullahbutt's full-sized avatar

Abdullah Butt abdullahbutt

  • Petersberg, Deutschland
View GitHub Profile
@abdullahbutt
abdullahbutt / MySQL DROP TABLE foreign keys
Created January 29, 2014 07:43
MySQL DROP TABLE foreign keys - The better way
MySQL drop table and foreign keys tip - the FOREIGN_KEY_CHECKS variable
By Alvin Alexander. Last updated: Aug 26, 2013
http://alvinalexander.com/blog/post/mysql/drop-mysql-tables-in-any-order-foreign-keys
MySQL DROP TABLE FAQ: Help, my MySQL database tables have a lot of foreign keys, and as a result it's a pain to use the MySQL DROP TABLE command in my scripts; they keep failing because of all the foreign keys. Is there something I can do to work around this DROP TABLE foreign keys problem?
With MySQL -- and any other database -- any time you want to rebuild your database schema, the first thing you normally do is drop all your old database tables with MySQL drop table statements, and then rebuild them with MySQL create table statements. When you do this, you'll often run into problems dropping the old database tables because of the foreign key relationships between the tables.
For instance, if an orders table has a foreign key link back to a customers table, you can't drop the customers table until you f
@abdullahbutt
abdullahbutt / big.php
Created January 30, 2014 14:48
ajax call sample
function fetchFilteredRecords(val)
{
if(val=="custom")
{
$("#custom_filtering").show();
}
else
{
@abdullahbutt
abdullahbutt / selectively dumping data with mysqldump
Last active August 29, 2015 13:56
selectively dumping data with mysqldump
Selectively dumping data with mysqldump
http://www.electrictoolbox.com/mysqldump-selectively-dump-data/
mysqldump is a command line tool for outputting table structures and data and can be used for backups etc. By default mysqldump will dump all data from a table, but it is possible to select which data to be exported with mysqldump. This post looks at how to do this.
The examples in this post have a table called "mytable" in a database called "test". mytable has three columns: mytable_id, category_id and name, and we will be selectively exporting data that matches a specific category_id.
Using mysqldump to dump all data from the table would look like this, subsituting [username] for your username (the -t flag suppresses the table creation sql from the dump):
@abdullahbutt
abdullahbutt / add border to font
Created February 21, 2014 12:29
how to add a border to your font
how to add a border to your font.
The right answer is:
#element {
color: yellow;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
@abdullahbutt
abdullahbutt / datepicker maxDate & minDate
Last active August 29, 2015 13:56
jquery datepicker maxdate or maxDate and mindate or minDate
maxDateType: Date or Number or String
Default: null
The maximum selectable date. When set to null, there is no maximum.
Multiple types supported:
• Date: A date object containing the maximum date.
• Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.
• String: A string in the format defined by the dateFormat option, or a relative date. Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today.
Code examples:
Initialize the datepicker with the maxDate option specified:
1 $( ".selector" ).datepicker({ maxDate: "+1m +1w" });
@abdullahbutt
abdullahbutt / placeholder using jquery
Last active August 29, 2015 13:57
placeholder using jquery
<script src="js/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function()
{
$('#password').attr('placeholder','Password');
$('#email').attr('placeholder','E-mail');
});
</script>
@abdullahbutt
abdullahbutt / regex
Created March 23, 2014 02:12
regular expressions character classes and other special escapes
Sequence Note Description
[...] [1] Match a character according to the rules of the
bracketed character class defined by the "...".
Example: [a-z] matches "a" or "b" or "c" ... or "z"
[[:...:]] [2] Match a character according to the rules of the POSIX
character class "..." within the outer bracketed
character class. Example: [[:upper:]] matches any
uppercase character.
(?[...]) [8] Extended bracketed character class
\w [3] Match a "word" character (alphanumeric plus "_", plus
@abdullahbutt
abdullahbutt / regex backslash
Created March 23, 2014 02:26
regular expressions backslash sequences
Backslash sequences
regular expressions backslash sequences
A backslash sequence is a sequence of characters, the first one of which is a backslash. Perl ascribes special meaning to many such sequences, and some of these are character classes. That is, they match a single character each, provided that the character belongs to the specific set of characters defined by the sequence.
Here's a list of the backslash sequences that are character classes. They are discussed in more detail below. (For the backslash sequences that aren't character classes, see perlrebackslash.)
@abdullahbutt
abdullahbutt / gist:10253010
Created April 9, 2014 10:37
get last word from url after a slash in php
get last word from url after a slash in php
preg_match("/[^\/]+$/", "http://www.mydomainname.com/m/groups/view/test", $matches);
$last_word = $matches[0]; // test
OR
Use basename with parse_url:
echo basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
@abdullahbutt
abdullahbutt / get and delete last word in URL
Last active August 29, 2015 13:58
get last word in URL and delete what is not necessary
get last word in URL and delete what is not necessary
if in $last_word you find also -0.htm then delete -0.htm
I explain my $last_word now shows test-0.htm
But I do not need -0.htm
I only need "test".
How do I say in PHP to delete -0.html and to grab only "test".
$last_word="-0.html";