Skip to content

Instantly share code, notes, and snippets.

View webmechanicx's full-sized avatar
🎯
reinventing

Farhadur Rahim webmechanicx

🎯
reinventing
View GitHub Profile
$(document).ready( function() {
$('#ClickWordList li').click(function() {
$("#txtMessage").insertAtCaret($(this).text());
return false
});
$("#DragWordList li").draggable({helper: 'clone'});
$(".txtDropTarget").droppable({
accept: "#DragWordList li",
drop: function(ev, ui) {
$(this).insertAtCaret(ui.draggable.text());
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>jQuery Examples for insertAtCaret</title>
<style type="text/css" media="Screen">
#maincontainer {
width: 960px;
margin: 0 auto;
}
@webmechanicx
webmechanicx / router.html
Created January 29, 2016 19:19 — forked from joakimbeng/router.html
A really simple Javascript router - one-directional data-binding with Object.observe()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Building a router</title>
<script>
// Put John's template engine code here...
(function () {
// A hash to store our routes:
@webmechanicx
webmechanicx / getInnerHTML.php
Created February 29, 2016 22:07
Get HTML,Text and Surrounded Tags
<?php
$html = <<< HTML
<body>
<h1>Hello,
<b>world!</b>
</h1>
</body>
HTML;
$dom = new DOMDocument;
@webmechanicx
webmechanicx / dom_tag_extractor.php
Created February 29, 2016 22:23
RegEx match open tags except XHTML self-contained tags
<?php
$selfClosing = explode(',', 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed');
$html = '
<p><a href="#">foo</a></p>
<hr/>
<br/>
<div>name</div>';
$dom = new DOMDocument();
@webmechanicx
webmechanicx / betweenTags.php
Created February 29, 2016 22:30
Simple PHP function to find anything between a tag
<?php
function betweenTags($string, $tagname)
{
$pattern = "#<\s*?$tagname\b[^>]*>(.*?)</$tagname\b[^>]*>#s";
preg_match($pattern, $string, $matches);
return $matches[1];
}
?>
@webmechanicx
webmechanicx / sluggify.php
Created February 29, 2016 23:10
To covert a string to SEO friendly Slug-URL
<?php
/* Sluggify - Simple Logic to turn a string to slug url
* To covert a string to SEO friendly
*/
$title = "To covert a string to SEO friendly"
$slugs = preg_replace('/\%/',' percentage',$title);
$slugs = preg_replace('/\@/',' at ',$slugs);
@webmechanicx
webmechanicx / object2array.php
Created March 3, 2016 00:15
Simple Demonstration object to Array
<?php
$post_id = array((object) (array(
'index_id' => 'Mahfuz',
)), (object) (array(
'index_id' => 'mstmhaque@gmail.com',
)), (object) (array(
'index_id' => 142,
)));
foreach ($post_id as $key => $value) {
@webmechanicx
webmechanicx / getMineType.php
Created March 15, 2016 22:13
Get the Mine-Type of a File
<?php
/**
* get mime data of the file.
* @return {String} mime-type of the given file
* @param $filename String
*/
function get_mime($filename){
preg_match("/\.(.*?)$/", $filename, $m); # Get File extension for a better match
switch(strtolower($m[1])){
case "js": return "application/javascript";
@webmechanicx
webmechanicx / canvas-upload.php
Created March 18, 2016 20:57 — forked from xjamundx/canvas-upload.php
php canvas base64 png decoder
<?php
// requires php5
define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);