Skip to content

Instantly share code, notes, and snippets.

View junaidpv's full-sized avatar

Junaid P V junaidpv

View GitHub Profile
@junaidpv
junaidpv / geolocation_distance.sql
Created September 16, 2011 10:58
Distance comparison of geolocations with a location given.
SET @c1 = PI()/180,
@c2 = PI()/360,
@r = 6378137,
@lat1 = ?,
@lng1 = ?;
SELECT latitude, longitude, distance
FROM (
SELECT *,
@lat2 := latitude,
@lng2 := longitude,
@junaidpv
junaidpv / ml-test.php
Created November 3, 2011 09:27
Malayalam text rendering using pango-cairo
<?php
//error_reporting(0);
$text = ("കണ്ണൂർ, പപ്പൻ, പൂച്ച");
$fontSize = "30";
$width = '300';
$s = new CairoImageSurface(CairoFormat::ARGB32, $width, 60);
$c = new CairoContext($s);
/* Set the background*/
$c->setSourceRGB(1,1,.27);
@junaidpv
junaidpv / cat-all-pages-count.py
Created November 22, 2011 11:17
Count all pages within a category and its sub-categories recursively
# -*- coding: utf-8 -*-
"""
Description
Count all pages within a category and its sub-categories recursively
@author Junaid
"""
import wikipedia
import catlib
@junaidpv
junaidpv / extract-common.js
Created August 2, 2012 03:47
Interproject links part from common.js of ml wiki
/*
== Interproject links ==
<pre> */
function Projectlinks() {
var elements = new Array();
var spans = document.getElementsByTagName('span');
// filter for projectlinks
for (var i=0, j=0; i<spans.length; i++) {
if (spans[i].className == 'interProject') {
@junaidpv
junaidpv / Malayalam-Mozhi.kms
Created October 4, 2012 16:39
Keymagic rules source code for Mozhi typing
/*
@NAME = "Malayalam Mozhi"
@DESCRIPTION = "Wikipedia a Mozhi"
@TRACK_CAPSLOCK = "TRUE"
@EAT_ALL_UNUSED_KEYS = "FALSE"
@US_LAYOUT_BASED = "TRUE"
@Icon = "ma.png"
*/
// author: Junaid (http://junaidpv.in)
// version: 1.2
@junaidpv
junaidpv / Malayalam-InScript.kms
Created October 4, 2012 16:40
Keymagic rules source code for InScript typing
/*
@NAME = "Malayalam InScript 5.0"
@DESCRIPTION = "Malayalam InScript Layout"
@TRACK_CAPSLOCK = "TRUE"
@EAT_ALL_UNUSED_KEYS = "FALSE"
@US_LAYOUT_BASED = "TRUE"
@Icon = "i.png"
*/
// author: Junaid (http://junaidpv.in)
// version: 0.1
@junaidpv
junaidpv / views_plugin_query_default.inc.patch
Created October 31, 2012 08:20
View the query executed by the view in Drupal 7
diff --git a/sites/all/modules/views/plugins/views_plugin_query_default.inc b/sites/all/modules/views/plugins/views_plugin_query_default.inc
index 39e8061..1a34443 100644
--- a/sites/all/modules/views/plugins/views_plugin_query_default.inc
+++ b/sites/all/modules/views/plugins/views_plugin_query_default.inc
@@ -1393,6 +1393,19 @@ class views_plugin_query_default extends views_plugin_query {
$query->range($offset, $limit);
}
+ $query_string = (string)$query;
+ $query_string = str_replace('{', '', $query_string);
@junaidpv
junaidpv / logout_all_users.php
Created November 14, 2012 08:22
Drupal 7 CLI script to logout all users and clear sessions
<?php
// Bootstrap
// Change chdir to the full path of your Drupal root
define('DRUPAL_ROOT', getcwd());
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
$_SERVER['REMOTE_ADDR'] = "127.0.0.1";
$_SERVER['REQUEST_METHOD'] = NULL;
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
@junaidpv
junaidpv / pull-all-repos.sh
Created February 23, 2013 11:35
Git pull all reositories residing on current directoy.
for i in */
do
echo "Opening directory $i..."
cd $i
git pull
cd ../
done
@junaidpv
junaidpv / zip.php
Created July 8, 2013 04:09 — forked from anonymous/zip.php
PHP script to zip a folder. It can be used on webhosts where functionality of zipping a folder is not enabled.
<?php
$path="../ctest";
$zip = new ZipArchive;
$zip->open('../ctest.zip', ZipArchive::CREATE);
if (false !== ($dir = opendir($path))) {
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..') {
$zip->addFile($path.DIRECTORY_SEPARATOR.$file);
//delete if need