Monday, April 3, 2017
Monday, February 6, 2017
Social Networks Token Playground
Generate Token:
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Did%2Cfirst_name%2Clast_name%2Cemail&version=v2.8
Get user by access token:
https://graph.facebook.com/me?fields=id,first_name,last_name,email,picture&access_token={ACCESS_TOKEN}
Generate Token:
https://developers.google.com/oauthplayground/
Get user by access token:
https://www.googleapis.com/oauth2/v1/userinfo?access_token={ACCESS_TOKEN}
Monday, September 12, 2016
Laravel 5.1 Useful Resources
- Update account password - http://teamnik.org/how-to-update-user-password-in-laravel5/
- User ACL with Entrust - http://itsolutionstuff.com/post/laravel-52-user-acl-roles-and-permissions-with-middleware-using-entrust-from-scratch-tutorialexample.html
- Track user last login time - http://coffeecupweb.com/capture-last-login-time-in-laravel-5/
- Retain old input & object state with create edit form - https://laracasts.com/discuss/channels/code-review/clean-way-to-inject-old-input
- Load settings from database -
http://stackoverflow.com/questions/32824781/laravel-load-settings-from-database
https://laracasts.com/discuss/channels/general-discussion/l5-best-way-to-load-settings-from-database - Custom Helper -
http://laravel-recipes.com/recipes/50/creating-a-helpers-file
http://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-on-laravel-5 - Cron Jobs
https://www.sitepoint.com/managing-cronjobs-with-laravel/
http://www.easylaravelbook.com/blog/2015/01/27/introducing-the-laravel-5-command-scheduler/
http://blog.mauriziobonani.com/laravel-cron-jobs-on-shared-hosting/
Hosting
- Host in a shared server - http://laraveldaily.com/laravel-and-shared-hosting-working-with-ftp-and-phpmyadmin/
Lumen
https://github.com/lucadegasperi/oauth2-server-laravel
http://esbenp.github.io/2015/05/26/lumen-web-api-oauth-2-authentication/
http://mrgott.com/joomla/24-integrate-oauth2-server-into-lumen-to-secure-your-restful-api-with-access-tokens
http://loige.co/developing-a-web-application-with-lumen-and-mysql/
Friday, January 8, 2016
Wednesday, November 25, 2015
Handle Cloning with jQuery Uniform
If you try to apply uniform styles for cloned elements, you may come across some weird situations where you don't get the expected output. Just try this if it applies to you also.
The bold text is the most important and it should be applied in the same order.
$.uniform.restore('.is_variant_enabled');
$('.is_variant_enabled').uniform();
[sourcecode language="javascript"]
$.uniform.restore('.is_variant_enabled');
var row = $("#tbl_variants").find('tr:eq(1)').clone();
$("#tbl_variants tbody").prepend(row);
$('.is_variant_enabled').uniform();
[/sourcecode]
The bold text is the most important and it should be applied in the same order.
$.uniform.restore('.is_variant_enabled');
$('.is_variant_enabled').uniform();
[sourcecode language="javascript"]
$.uniform.restore('.is_variant_enabled');
var row = $("#tbl_variants").find('tr:eq(1)').clone();
$("#tbl_variants tbody").prepend(row);
$('.is_variant_enabled').uniform();
[/sourcecode]
Tuesday, October 27, 2015
Export Magento Product Categories to custom table
[sourcecode language="php"]
<?php
ini_set('max_execution_time', 1500);
error_reporting(-1);
ini_set('display_errors', 1);
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url')
->addAttributeToSelect('is_active');
foreach ($categories as $category) {
$entity_id = $category->getId();
$name = mysql_real_escape_string($category->getName());
$url_key = $category->getUrlKey();
$url_path = $category->getUrl();
$is_active = $category->getIsActive();
$now = time();
$catids = array();
foreach ($category->getParentCategories() as $parent) {
$catids[] = $parent->getId();
}
unset($catids[count($catids) - 1]);
$parent = NULL;
if (empty($catids)) {
$parent = NULL;
} else {
$parent = array_pop($catids);
}
$con = mysql_connect("HOST", "USER", "PASSWORD");
mysql_select_db("DB", $con) or die("");
mysql_query("INSERT INTO `categories`(`id`, `name`, `slug`, `parent_id`, `enabled`, `modified_at`, `modified_by`) VALUES ('$entity_id', '$name', '$url_key', '$parent' ,'$is_active', '$now', 1)") or die(mysql_error());
}
[/sourcecode]
<?php
ini_set('max_execution_time', 1500);
error_reporting(-1);
ini_set('display_errors', 1);
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url')
->addAttributeToSelect('is_active');
foreach ($categories as $category) {
$entity_id = $category->getId();
$name = mysql_real_escape_string($category->getName());
$url_key = $category->getUrlKey();
$url_path = $category->getUrl();
$is_active = $category->getIsActive();
$now = time();
$catids = array();
foreach ($category->getParentCategories() as $parent) {
$catids[] = $parent->getId();
}
unset($catids[count($catids) - 1]);
$parent = NULL;
if (empty($catids)) {
$parent = NULL;
} else {
$parent = array_pop($catids);
}
$con = mysql_connect("HOST", "USER", "PASSWORD");
mysql_select_db("DB", $con) or die("");
mysql_query("INSERT INTO `categories`(`id`, `name`, `slug`, `parent_id`, `enabled`, `modified_at`, `modified_by`) VALUES ('$entity_id', '$name', '$url_key', '$parent' ,'$is_active', '$now', 1)") or die(mysql_error());
}
[/sourcecode]
Tuesday, October 20, 2015
Friday, October 2, 2015
Change Database Collation with PHP
This little sql statement can change the collation in your database including tables, columns and everywhere. This is something phpMyAdmin can not handle completely.
Credits goes to original poster.
[sourcecode language="php"]
$conn1=new MySQLi("localhost","root","","exam_db");
if($conn1->connect_errno){
echo mysqli_connect_error();
exit;
}
$res=$conn1->query("show tables") or die($conn1->error);
while($tables=$res->fetch_array()){
$conn1->query("ALTER TABLE $tables[0] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci") or die($conn1->error);
}
echo "The collation of your database has been successfully changed!";
$res->free();
$conn1->close();
[/sourcecode]
Credits goes to original poster.
[sourcecode language="php"]
$conn1=new MySQLi("localhost","root","","exam_db");
if($conn1->connect_errno){
echo mysqli_connect_error();
exit;
}
$res=$conn1->query("show tables") or die($conn1->error);
while($tables=$res->fetch_array()){
$conn1->query("ALTER TABLE $tables[0] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci") or die($conn1->error);
}
echo "The collation of your database has been successfully changed!";
$res->free();
$conn1->close();
[/sourcecode]
Monday, September 14, 2015
Sunday, September 13, 2015
Google Map InfoBox
[sourcecode language="html"]
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<script type="text/javascript">
var ib = null;
var theMap = null;
function initialize() {
var latlng = new google.maps.LatLng(55.672962361614566, 12.56587028503418);
var myMapOptions = {
zoom: 15
,center: latlng
,mapTypeId: google.maps.MapTypeId.ROADMAP
,streetViewControl: false
};
theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
// namn
var name=[];
name.push('Test 1');
name.push('Test 2');
// positioner
var position=[];
position.push(new google.maps.LatLng(55.667093265894245,12.581255435943604));
position.push(new google.maps.LatLng(55.66453963191134, 12.584795951843262));
// infoboxes
var infobox = [];
infobox.push("<div>Hello 1</div>");
infobox.push("<div>Hello 2</div>");
ib = new InfoBox({});
for (i = 0; i < position.length; i += 1) {
// Call function
createMarkers(position[i], infobox[i], name[i]);
}
function createMarkers(position,content,name) {
// alert("createMarkers("+position+","+content+","+name+")");
var marker = new google.maps.Marker({
map: theMap,
draggable: false,
position: position,
visible: true,
title: name
});
var boxText = document.createElement("div");
boxText.style.cssText = "background: yellow; width: 300px; height: 70px; padding: 5px;";
boxText.innerHTML = content;
var myOptions = {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-37, -120)
,zIndex: null
,boxStyle: {
background: "url('tipbox.gif') no-repeat"
,opacity: 1
,width: "300px"
}
,closeBoxMargin: "5px 5px 5px 5px"
,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
google.maps.event.addListener(marker, "click", function (e) {
alert("click");
ib.setOptions(myOptions);
ib.open(theMap, this);
});
ib.open(theMap, marker);
ib.hide();
}
}
</script>
<title>Creating and Using an InfoBox</title>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 100%; height: 400px"></div></body>
</html>
[/sourcecode]
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<script type="text/javascript">
var ib = null;
var theMap = null;
function initialize() {
var latlng = new google.maps.LatLng(55.672962361614566, 12.56587028503418);
var myMapOptions = {
zoom: 15
,center: latlng
,mapTypeId: google.maps.MapTypeId.ROADMAP
,streetViewControl: false
};
theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
// namn
var name=[];
name.push('Test 1');
name.push('Test 2');
// positioner
var position=[];
position.push(new google.maps.LatLng(55.667093265894245,12.581255435943604));
position.push(new google.maps.LatLng(55.66453963191134, 12.584795951843262));
// infoboxes
var infobox = [];
infobox.push("<div>Hello 1</div>");
infobox.push("<div>Hello 2</div>");
ib = new InfoBox({});
for (i = 0; i < position.length; i += 1) {
// Call function
createMarkers(position[i], infobox[i], name[i]);
}
function createMarkers(position,content,name) {
// alert("createMarkers("+position+","+content+","+name+")");
var marker = new google.maps.Marker({
map: theMap,
draggable: false,
position: position,
visible: true,
title: name
});
var boxText = document.createElement("div");
boxText.style.cssText = "background: yellow; width: 300px; height: 70px; padding: 5px;";
boxText.innerHTML = content;
var myOptions = {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-37, -120)
,zIndex: null
,boxStyle: {
background: "url('tipbox.gif') no-repeat"
,opacity: 1
,width: "300px"
}
,closeBoxMargin: "5px 5px 5px 5px"
,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
google.maps.event.addListener(marker, "click", function (e) {
alert("click");
ib.setOptions(myOptions);
ib.open(theMap, this);
});
ib.open(theMap, marker);
ib.hide();
}
}
</script>
<title>Creating and Using an InfoBox</title>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 100%; height: 400px"></div></body>
</html>
[/sourcecode]
Thursday, August 27, 2015
Prepend Items to Bootstrap Typeahead
This is a little code snippet for manually adding static items along with typeahead suggestions list. This can be used to prepend or append items. I'm using biggora/bootstrap-ajax-typeahead
You only need to look for render event of the plugin and inject your code.
[sourcecode language="javascript"]
$("#customer").typeahead({
onSelect: function(item) {
...
},
updater: function(item) {
return item;
},
highlighter: function(name) {
...
},
ajax: {
...
},
render: function(items) {
var uber = {render: $.fn.typeahead.Constructor.prototype.render};
uber.render.call(this, items);
this.$menu.prepend('<li class="nostyle"><a href="#" autocomplete="off" data-toggle="modal" data-target="#itemModal"><i class="fa fa-plus"></i> New Customer</a></li>');
return this;
}
});
[/sourcecode]
You only need to look for render event of the plugin and inject your code.
[sourcecode language="javascript"]
$("#customer").typeahead({
onSelect: function(item) {
...
},
updater: function(item) {
return item;
},
highlighter: function(name) {
...
},
ajax: {
...
},
render: function(items) {
var uber = {render: $.fn.typeahead.Constructor.prototype.render};
uber.render.call(this, items);
this.$menu.prepend('<li class="nostyle"><a href="#" autocomplete="off" data-toggle="modal" data-target="#itemModal"><i class="fa fa-plus"></i> New Customer</a></li>');
return this;
}
});
[/sourcecode]
Subscribe to:
Posts (Atom)
How to enable CORS in Laravel 5
https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...
-
Today we are going to build another restful web service in eclipse using gson library. When client makes a request, the application queries ...
-
To import Excel data, first you need to have a Excel reader. It should be accurate enough to interpret Excel data as expected. There 's ...