Skip to content

Instantly share code, notes, and snippets.

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

Deepak Lamichhane dlamichhane

🏠
Working from home
View GitHub Profile
when "email"
regex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
when "url"
regex = /^(http:\/\/|https:\/\/)?(www.)?[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3})([.]?[a-zA-Z]{2})?(\/\S*)?$/i
when "number"
regex = /^\d{1,3}(\,?\d{3})*$/
when "time"
regex = /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/
when "date"
regex = /^(\d{1,2})[\/|-|\.|\s](\d{1,2})[\/|-|\.|\s](\d{2,4})$/
when "url"
regex = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
test match scenario:
http://www.en.hotmail-f.com.np
https://www.apple.co.uk
http://www.apple.com
http://www.apple.com
http://w3.apple.tv
http://www.apple-apple.com
@dlamichhane
dlamichhane / raw_tag.rb
Created August 17, 2011 05:40 — forked from phaer/raw_tag.rb
Raw tag for jekyll. Keeps liquid from parsing text betweeen {% raw %} and {% endraw %}
module Jekyll
class RawTag < Liquid::Block
def parse(tokens)
@nodelist ||= []
@nodelist.clear
while token = tokens.shift
if token =~ FullToken
if block_delimiter == $1
end_tag
@dlamichhane
dlamichhane / HTTP Status Code
Created December 14, 2012 19:43
HTTP Status Code
The Status-Code element is a 3-digit integer result code of the attempt to understand and
satisfy the request. The first digit of the Status-Code defines the class of response. The
last two digits do not have any categorization role.There are 5 values for the first digit:
1xx: Informational - Request received, continuing process
2xx: Success - The action was successfully received,understood, and accepted
3xx: Redirection - Further action must be taken in order to complete the request
4xx: Client Error - The request contains bad syntax or cannot be fulfilled
5xx: Server Error - The server failed to fulfill an apparently valid request
@dlamichhane
dlamichhane / gist:5894774
Created June 30, 2013 11:06
Solution to problem of installing native gems on windows machine
Reference: http://rubyonwindowsguides.github.io/book/ch02-05.html
Installing Native Gems
Now we are fully equipped for Ruby development on Windows. Yet problem of installing native gems requires our attention and better explanation. DevKit’s smoke test passed without problem but does it mean we can install any gem written in C/C++? Unfortunately the answer is no.
Native gems might depend on other libraries which are hard, or sometimes, impossible to build on Windows. Example of such a gem is Nokogiri, HTML and XML parser for Ruby, built upon Libxml2 library. Libxml2 is XML parser and toolkit written in C. If you want to know how to deal, at least partially, with such a libraries you should continue reading this chapter. Otherwise you can freely skip to the section “Installing Ruby On Rails”.
Just for illustration try to install Nokogiri from sources. Installation will fail with quite a long message printed out in the Command Prompt. Leaving out irrelevant parts output looks similar to following:
@dlamichhane
dlamichhane / Solution to native gems on windows
Last active May 20, 2022 16:48
Installing Native gems on windows
I Copied from the following URL:
1) http://rubyonwindowsguides.github.io/book/ch02-05.html
Now we are fully equipped for Ruby development on Windows. Yet problem of installing native gems requires our attention and better explanation. DevKit’s smoke test passed without problem but does it mean we can install any gem written in C/C++? Unfortunately the answer is no.
Native gems might depend on other libraries which are hard, or sometimes, impossible to build on Windows. Example of such a gem is Nokogiri, HTML and XML parser for Ruby, built upon Libxml2 library. Libxml2 is XML parser and toolkit written in C. If you want to know how to deal, at least partially, with such a libraries you should continue reading this chapter. Otherwise you can freely skip to the section “Installing Ruby On Rails”.
c:\>gem install nokogiri --platform=ruby
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it
gem install bundler
# 1. Get edge Rails source (master branch)
git clone https://github.com/rails/rails.git
@dlamichhane
dlamichhane / gist:6784142
Created October 1, 2013 19:56
Install LAMP stack on Ubuntu
Install LAMP stack on unix
Followed this steps: http://www.howtoforge.com/ubuntu_lamp_for_newbies
Install Apache
1) sudo apt-get install apache2
Install php5
def nep_to_eng(*args)
date = args.map{|val| val.to_i}
date_error = date_valid(date, "np")
unless date_error.empty?
return date_error.collect{ |error| "Enter appropriate #{error}"}
else
en_start_year = 1943; en_start_month = 4; en_start_day = 14 - 1
np_start_year = 2000; np_start_month = 1; np_start_day = 1
day_of_week = 4 - 1