Skip to content

Instantly share code, notes, and snippets.

View devudit's full-sized avatar
🎓
Focusing

Udit Rawat devudit

🎓
Focusing
View GitHub Profile
@devudit
devudit / initilize.html
Last active November 22, 2017 06:27
Run code before and after CkEditor Initilize
<textarea name="editor"></textarea>
@devudit
devudit / custom-token.php
Created November 21, 2017 07:59
Create Custom Tokens In Drupal 8
<?php
/**
* @file
* contains custom token declaration script.
*/
/**
* Implements hook_token_info().
*/
function custom_token_info(){
$types['custom_type'] = array(
@devudit
devudit / query-string.js
Created May 25, 2017 06:16
How to get Query String using javascript
/**
* @description Below function will return a object of query string variable
**/
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
@devudit
devudit / get-ip-address.php
Created November 7, 2016 07:07
Getting the Correct IP Address With PHP
<?php
function get_ip() {
//Just get the headers if we can or else use the SERVER global
if ( function_exists( 'apache_request_headers' ) ) {
$headers = apache_request_headers();
} else {
$headers = $_SERVER;
}
@devudit
devudit / multiple-hook.php
Created August 1, 2016 10:10
Multiple Hooks in one extension - Expression Engine
<?php
$hooks = array(
"template_fetch_template" => "template_fetch_template",
"store_order_item_add_start" => "store_order_item_add_start"
);
foreach ($hooks as $hook => $method){
$data = array(
'class' => __CLASS__,
'method' => $hook,
@devudit
devudit / remove-duplicate.js
Created July 15, 2016 12:22
Remove duplicate element from array in javascript Or remove duplicate element after concat in javascript
Array.prototype.unique = function() {
var a = this.concat();
for(var i=0; i<a.length; ++i) {
for(var j=i+1; j<a.length; ++j) {
if(a[i] === a[j])
a.splice(j--, 1);
}
}
return a;
};
@devudit
devudit / get-all-key.php
Created July 9, 2016 01:54
Get all keys from a array that start with a certain string
<?php
/*
EXAMPLE ARRAY:-
array(
[field_ft_channel_id] => value of field
[field_ft_status] => value of field
[field_ft_author_id] => value of field
[field_id_14] => value of field
[field_id_15] => value of field
[field_id_16] => value of field|value of field
@devudit
devudit / category-description-wysiwyg.php
Created July 8, 2016 08:54
How to add ckeditor / wysiwyg editor in category description field in expression engine.
<?php
/*
* HOW TO:-
* Here is simple accessories code for adding ckeditor / wysiwyg editor in category description field in expression engine.
* create a directory as /system/expressionengine/third_party/eme_utills
* create a accessories addon file like /system/expressionengine/third_party/eme_utills/acc.eme_utills.php
* Now add the following code to it
*/
/**
* EME UTILLS Accessory
@devudit
devudit / wrap-colorbox.js
Created July 7, 2016 12:00
Wrap colorbox main div into another
$.colorbox({
open: true,
height: 500,
width: 500,
onComplete: function() {
$("#colorbox").wrap("<div id='colorbox_wrapper' />")
},
onCleanup: function() {
$("#colorbox").unwrap("<div id='colorbox_wrapper' />")
}
@devudit
devudit / get-image-by-tag.js
Created July 7, 2016 09:56
Get Instagram image data using javascript/jquery
var token = '<access_token>',
hashtag='<tag>', // hashtag without # symbol
num_photos = 4;
$.ajax({
url: 'https://api.instagram.com/v1/tags/' + hashtag + '/media/recent',
dataType: 'jsonp',
type: 'GET',
data: {access_token: token, count: num_photos},
success: function(data){