Skip to content

Instantly share code, notes, and snippets.

View niksmac's full-sized avatar
🇮🇳
🧜 Merperson

Nikhil M niksmac

🇮🇳
🧜 Merperson
View GitHub Profile
<html>
<head>
<title>jsonp test</title>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(function(){
$('#select_link').click(function(e){
e.preventDefault();
console.log('select_link clicked');
<?php
/**
* Implements hook_preprocess_views_view_unformatted().
*/
function YOUR_THEME_preprocess_views_view_unformatted(&$variables) {
// Determine if this view's content should render in columns.
// @see: _YOUR_THEME_views_columns();
_YOUR_THEME_views_columns($variables, array(
'articles|page' => 2,
<?php
/**
* UUID class
*
* The following class generates VALID RFC 4122 COMPLIANT
* Universally Unique IDentifiers (UUID) version 3, 4 and 5.
*
* UUIDs generated validates using OSSP UUID Tool, and output
* for named-based UUIDs are exactly the same. This is a pure
* PHP implementation.
@niksmac
niksmac / drupal-permissionfix.php
Created December 4, 2014 06:01
Automatically Securing file permissions and ownership for Drupal 7
<?php
function SetPerms($dir = ".") {
$listDir = array();
if($handler = opendir($dir)) {
while (($sub = readdir($handler)) !== FALSE) {
if ($sub != "." && $sub != "..") {
if(is_file($dir."/".$sub)) {
echo "File: $dir/$sub\n";
chmod($dir."/".$sub, 0644);
@niksmac
niksmac / cache_get.php
Created December 26, 2014 08:15
Drupal Gotcha : Cache_get() Returns Expired Items
cache_get() returns $cache objects even if the cached item is stale (expired)
function custom_fn_get_data() {
// Return the cached data
$cache = cache_get('custom:fn_get_data');
if (!$cache) {
// Some expensive processing to build the data.
$data = complicated_recursion_and_loops_on_lots_of_data();
// Cache the data and rebuild it every hour
@niksmac
niksmac / gist:a18a504309224d3adcb0
Created January 21, 2015 11:51
Drupal 7 Location Calculate distance between 2 location fields
Location module has the function location_distance_between() (also in D7).
It passes the call on to function earth_distance($longitude1, $latitude1, $longitude2, $latitude2), which lives inside the earth.inc file in the same package.
See also: http://en.wikipedia.org/wiki/Great-circle_distance, which points out some of the intricacies of numerical calculation and accuracy of long vs short distances.
@niksmac
niksmac / config.json
Last active August 29, 2015 14:15 — forked from anonymous/config.json
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",
@niksmac
niksmac / onajaxsuccess.js
Created November 18, 2011 06:04
Works on every ajax success from a page
$(document).ready( function () {
$('body:last-child').bind('ajaxSuccess', function() {
init_ajax_sucess();
});
});
function init_ajax_sucess() {
// Do something
}
Array
(
[hook_menu] => 6744
[hook_uninstall] => 4742
[hook_perm(ission)] => 4012
[hook_install] => 3751
[hook_theme] => 3525
[hook_schema] => 3003
[hook_help] => 2465
[hook_form_alter] => 2273
@niksmac
niksmac / socketevents.js
Created January 6, 2014 09:25
Socket IO events with description
// emit to all sockets (aka publish)
// including yourself
io.sockets.emit('messageName', {thisIs: 'theMessage'});
// broadcast to a room (aka publish)
// excluding yourself, if you're in it
socket.broadcast.to('roomName').emit('messageName', {thisIs: 'theMessage'});
// emit to a room (aka publish)
// including yourself