Skip to content

Instantly share code, notes, and snippets.

View harshamv's full-sized avatar
🏠
Working from home

Harsha MV harshamv

🏠
Working from home
View GitHub Profile
@harshamv
harshamv / select.rb
Created July 6, 2014 08:15
Auto-submitting select tag
If you want your form to be submitted when user selects something, use:
:onchange => "this.form.submit();"
For example:
select_tag "people", "<option>David</option>", :onchange => "this.form.submit();"
@harshamv
harshamv / friendly_id.rb
Created July 2, 2014 06:36
Friendly_id smaller conflict slug
# over writing the conflict slug
module FriendlyId
module Slugged
def resolve_friendly_id_conflict(candidates)
candidates.first + friendly_id_config.sequence_separator + SecureRandom.hex(3)
end
end
end
@harshamv
harshamv / wiki.php
Last active August 29, 2015 14:03
Get First Para from Wikipedia
<?php
$query = $_GET['query'];
$url = "http://en.wikipedia.org/w/api.php?action=parse&page=$query&format=json&prop=text&section=0";
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "TestScript"); // required by wikipedia.org server; use YOUR user agent with YOUR contact information. (otherwise your IP might get blocked)
$c = curl_exec($ch);
# Google Direction API
include HTTParty
format :json
def api_key
# Your API key
end
def direciton_api_url
/*
* An example of how to use a Google Map overlay to display a label on top of marker.
* This is a slight re-work of http://www.tdmarketing.co.nz/blog/2011/03/09/create-marker-with-custom-labels-in-google-maps-api-v3/
* I suggest you rather view that blog post, this code is pasted here purely for my own personal reference.
*/
var
point = {
lat: 37.8478115,
long: 15.2934327
maps.google.com/maps?q=25.279139,51.551230
#!/bin/bash
# mongodump reference: http://www.nacaolivre.com.br/servidor/mysql-backup-com-mysqldump/
# Author: Lazaro Lima - www.lazarolima.com.br
#
S3_BUCKET_NAME="condomundo-databases-snapshots"
S3_BUCKET_PATH="mysql-backups"
MYSQLROOT="yourUserName"
MYSQLPASS="yourPassword"
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<link href="https://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
@harshamv
harshamv / .htaccess
Created June 27, 2014 15:19
GZIP Apache Server
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
# Netscape 4.x has some problems
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
function hideAddressBar()
{
if(!window.location.hash)
{
if(document.height < window.outerHeight)
{
document.body.style.height = (window.outerHeight + 50) + 'px';
}
setTimeout( function(){ window.scrollTo(0, 1); }, 50 );