Skip to content

Instantly share code, notes, and snippets.

View kitwalker12's full-sized avatar

Kunwar Aditya Raghuwanshi kitwalker12

View GitHub Profile
@kitwalker12
kitwalker12 / check_string.rb
Last active August 29, 2015 13:56
check if string is float and/or whole number
def is_number?(str)
true if Float(str) rescue false
end
def prettify(str)
str = str.to_f
str.to_i == str ? str.to_i : str
end
@kitwalker12
kitwalker12 / autoresizetext.js
Created April 24, 2014 19:17
auto resize text
var resizeText = function(el) {
elNewFontSize = (parseInt($(el).css('font-size').slice(0, -2)) - 1) + 'px'
console.log(elNewFontSize);
$(el).css('font-size', elNewFontSize)
};
elements = $('.long-text');
elements.each(function(index, el) {
while(el.scrollWidth > el.offsetWidth) {
resizeText(el);
@kitwalker12
kitwalker12 / gif.rb
Created May 20, 2014 20:52
Random Gif generator
require 'httparty'
response = HTTParty.get("http://api.giffy.co/gifs/limit/1/offset/#{rand(8000)}")
@gif = JSON.parse(response.body)['gifs'].first['url']
@kitwalker12
kitwalker12 / all_checkboxes.js
Created August 20, 2014 07:09
Check all checkboxes in a page
$(function(){
$('input:checkbox').attr('checked', 'checked');
});
@kitwalker12
kitwalker12 / my_controller.rb
Last active August 29, 2015 14:07
Polling Worker Contoller in Rails
class MyController < ApplicationController
def new
end
def create
@job_id = MyWorker.perform_async(my_params)
render :status => :accepted, :json => { jobId: @job_id }
end
def fetch
@kitwalker12
kitwalker12 / javascript_compare.js
Created October 9, 2014 21:25
Javascript compare dates
// Source: http://stackoverflow.com/questions/497790
var dates = {
convert:function(d) {
// Converts the date in d to a date-object. The input can be:
// a date object: returned without modification
// an array : Interpreted as [year,month,day]. NOTE: month is 0-11.
// a number : Interpreted as number of milliseconds
// since 1 Jan 1970 (a timestamp)
// a string : Any format supported by the javascript engine, like
// "YYYY/MM/DD", "MM/DD/YYYY", "Jan 31 2009" etc.
@kitwalker12
kitwalker12 / devtools.js
Created October 9, 2014 22:44
chrome devtools tips
monitorEvents(window, 'click');
monitorEvents(window, 'scroll');
//After store as global variable, save to clipboard
copy($_)
//timeline
console.timeline('xxx');
console.timelineEnd('xxx');
@kitwalker12
kitwalker12 / cors.xml
Last active August 29, 2015 14:07
CORS S3
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
</CORSRule>
<CORSRule>
<AllowedOrigin>http://mydomain.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
@kitwalker12
kitwalker12 / method_message.rb
Created October 22, 2014 18:53
Method and Message (from Rubytapas)
class TeaClock
attr_accessor :timer
attr_accessor :ui
def initialize(minutes)
#Tie ui object
self.ui = StdioUi.new
#Tie timer object. Pass ui object so that the final implementation of notify (after plugins are loaded) is called
self.timer = SleepTimer.new(minutes, ui)
#Extend ui or timer objects
@kitwalker12
kitwalker12 / email.html
Created October 23, 2014 23:50
html email boilerplate
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Your Message Subject or Title</title>
<style type="text/css">
/* Based on The MailChimp Reset INLINE: Yes. */
/* Client-specific Styles */
#outlook a {padding:0;} /* Force Outlook to provide a "view in browser" menu link. */