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 / 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 / SiteMaintenanceTemplate.html
Last active November 13, 2023 14:52 — forked from pitch-gist/gist:2999707
Simple Maintenance Template Page - HTML CSS
<!DOCTYPE html>
<html lang="en">
<head>
<title>Site Maintenance</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
@niksmac
niksmac / ethtxminer.js
Created April 1, 2016 01:51
Ethereum Blockchain Mine only when there is a transaction
var mining_threads = 1
function checkWork() {
if (eth.getBlock("pending").transactions.length > 0) {
if (eth.mining) return;
console.log("== Pending transactions! Mining...");
miner.start(mining_threads);
} else {
miner.stop(0); // This param means nothing
console.log("== No transactions! Mining stopped.");
@niksmac
niksmac / balanced-parentheses.php
Last active May 9, 2016 06:52
Prints all combinations of n-pairs of balanced parentheses using PHP
<?php
function printbraces($n) {
if($n>0) {
start_printing("", $n, $n);
}
}
function start_printing($s, $o, $c) {
if($o > $c)
return;
if($o == 0 && $c == 0){
@niksmac
niksmac / index.html
Created May 27, 2016 02:30
Simple HTML CSS site maintenance tempalte - responsive, CSS, Center middle
<!DOCTYPE html>
<html lang="en">
<head>
<title>Site Maintenance</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Lato:400,900' rel='stylesheet' type='text/css'>
<style>
h1 { font-size: 50px; color: #d33682; font-weight: 900; line-height: 3.5rem}
@niksmac
niksmac / optimize-images.sh
Created July 30, 2016 05:51
Optimize images for faster loading websites
#!/bin/bash
echo `date` >> /root/optipng.log
find /var/www/html/mmdrupal/sites/default/files/styles/ -mtime -2 -iname '*.png' -print0 | \
xargs -0 optipng -o7 -log /root/optipng.log -preserve
echo `date` >> /root/jpegoptim.log
find /var/www/html/mmdrupal/sites/default/files/styles/ -mtime -2 -iname '*.jpg' -print0 | \
xargs -0 jpegoptim --max=90 --preserve --totals >> /root/jpegoptim.log

Keybase proof

I hereby claim:

  • I am niksmac on github.
  • I am niksmac (https://keybase.io/niksmac) on keybase.
  • I have a public key ASDIN9pUfXhvZO_R2C2Co5XPM8HjOBrfznFX0WD80TDEVwo

To claim this, I am signing this object:

@niksmac
niksmac / duplicatedb.sh
Last active August 25, 2016 04:02
MySQL script to copy/duplicate database from linux terminal.
#!/bin/bash
DBUSER=user
DBPASSWORD=pwd
DBSNAME=sourceDb
DBNAME=destinationDb
DBSERVER=localhost
fCreateTable=""
fInsertData=""