Skip to content

Instantly share code, notes, and snippets.

View mindaslab's full-sized avatar

Karthikeyan A K mindaslab

View GitHub Profile
#include<stdio.h>
int main(){
printf("Hello World!\n");
return 0;
}
def ist(time)
time.in_time_zone(TZInfo::Timezone.get('Asia/Kolkata'))
end
@mindaslab
mindaslab / humanize.rb
Created January 24, 2012 17:00
humanizing time
def humanize secs
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name|
if secs > 0
secs, n = secs.divmod(count)
"#{n.to_i} #{name}"
end
}.compact.reverse.join(' ')
end
p humanize 1234
@mindaslab
mindaslab / geo.html
Created February 2, 2012 17:13
Geolocation
<html>
<head></head>
<body>
<script>
navigator.geolocation.getCurrentPosition(GetLocation);
function GetLocation(location) {
alert(location.coords.latitude);
alert(location.coords.longitude);
alert(location.coords.accuracy);
}
@mindaslab
mindaslab / hello.c
Created March 7, 2012 05:20
My first C
#include <stdio.h>
int main(){
return 0;}
@mindaslab
mindaslab / addtive_solver.rb
Created March 25, 2012 07:37
Putsall possible additive combinations for an number
class Array
def sum
total = 0
for element in self
total += element
end
total
end
def increment base = 1
@mindaslab
mindaslab / enter_get.js
Created May 19, 2012 10:02
jQuery code for enter key capture
$('#input_text').keyup(function(e) {
//alert(e.keyCode);
if(e.keyCode == 13) {
alert('Enter key was pressed.');
}
});
@mindaslab
mindaslab / links_and_buttons.html
Created June 20, 2012 15:15
Twitter Bootstrap Book
@mindaslab
mindaslab / search.rb
Last active December 19, 2015 14:49
Active Record Search For Rails 3, 4
##
# A simple search method
def self.search text
columns = [:name, :roll_no, :address, :city, :pin, :ph]
words = text.downcase.split(/\s+/)
query_array_2 = []
for word in words
query_array = []
for column in columns
query_array << "lower(#{column}) like '%#{word}%'"
@mindaslab
mindaslab / uuid_creation_time_extraction.rb
Last active December 21, 2015 17:28
Simple UUID examples
require 'rubygems'
require 'simple_uuid'
uuid = SimpleUUID::UUID.new
uuid.to_guid # actually this is what I have stored in my database
puts Time.at(SimpleUUID::UUID.new(uuid.to_guid).seconds)