Skip to content

Instantly share code, notes, and snippets.

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

Nikhil M niksmac

🇮🇳
🧜 Merperson
View GitHub Profile
@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
@niksmac
niksmac / gist:8554406
Created January 22, 2014 06:44
How to install the latest version of node.js
$ cd /usr/local/src
$ git clone https://github.com/joyent/node.git
$ cd node
$ git checkout v0.10.24 #Try checking www.nodejs.org for what the stable version is
$ ./configure && make && sudo make install
$ which node #Confirm installation
#You may want to put the node executables in your path as well for easier use. Add this line to your ~/.profile or ~/.bash_profile or ~/.bashrc or ~/.zshenv
$ export PATH=$PATH:/opt/node/bin
@niksmac
niksmac / mongo_install.bash
Created January 22, 2014 06:51
Install Latest version of MongoDB in ubuntu.
# Copy the following into a new file named `mongo_install.bash` in your home directory:
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | tee -a /etc/apt/sources.list.d/10gen.list
apt-get -y update
apt-get -y install mongodb-10gen
# Execute the following from your home directory:
$ sudo bash ./mongo_install.bash
<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 / detect-mobile-browser.js
Last active January 17, 2024 08:48
Nodejs Express code to redirect mobile user agets
var express = require('express'),
app = express();
app.listen(80);
app.get('/', function(req, res){
var ua = req.header('user-agent');
// Check the user-agent string to identyfy the device.
if(/mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile|ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(ua)) {
res.sendfile(__dirname + '/mobile.html');
} else {
res.sendfile(__dirname + '/index.html');
@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);