Skip to content

Instantly share code, notes, and snippets.

View kvirani's full-sized avatar

Khurram Virani kvirani

View GitHub Profile
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
@kvirani
kvirani / average.js
Created December 16, 2016 18:05 — forked from davejellicoe/average.js
javascript samples from week 1
function average(list) {
var sum = 0;
for (var num in list) {
sum += list[num];
}
return sum / list.length;
}
console.log(average([20, 21, 220, 54]));
@kvirani
kvirani / 0_reuse_code.js
Last active April 8, 2018 02:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# Lambdas, Proc.new, and Blocks - Bitmaker breakout session
# Friday March 8, 2013
## LAMBDAS
# Basic Usage:
# Think of lambdas as methods that have no name and instead they can be assigned to a variable and thus be passed around.
l = lambda {"do or do not"}
puts l.call # returns => do or do not
# http://stackoverflow.com/questions/6312448/how-to-disable-logging-of-asset-pipeline-sprockets-messages-in-rails-3-1
# https://github.com/rails/rails/pull/4501
# https://github.com/rails/rails/pull/4512
if Rails.env.development?
#Rails.application.assets.logger = false #Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
# The controller method for the same is as below
def update_additional_details
@user = current_user
@user.profile.display_education_details(show_details_for_profile?(:education))
@user.profile.display_experience_details(show_details_for_profile?(:experience))
@user.profile.display_linkedin_details(show_details_for_profile?(:linkedin_profile))
@user.profile.detail[:linkedin_profile][:data] = params[:linkedin_profile_data]
if @user.profile.save
redirect_to additional_details_user_path(@user), :notice => _("successfully_updated")
def url_valid
url = URI.parse(get_linkedin_profile)
unless %w( http https ).include?(url.scheme) && (url.hostname.include? "linkedin") && !url.path.blank?
errors.add(:detail, "Please Enter a Valid Linkedin Profile URL")
end
rescue URI::InvalidURIError => e
errors.add(:detail, "Please Enter a Valid Linkedin Profile URL")
end
#This method works fine but How can I better handle invalid string values like linkedin_url = ">>>>>" ?