Skip to content

Instantly share code, notes, and snippets.

View coderhs's full-sized avatar
🎯
Focusing

Harisankar P S coderhs

🎯
Focusing
View GitHub Profile
@coderhs
coderhs / Alarm.rb
Last active December 14, 2015 23:48
Why my alarm stopped working.
class Alarm
def initialize(alarm_time,music = "/mount/data2/Songs/11.Mazhathullikal.mp3")
@alarm_time = alarm_time
@music = music
@run = true
end
def its_time
system("vlc #{@music} --volume 512")
end
message.body.gsub(/https*:\/\/[a-zA-z0-9\-\.]*.[a-zA-Z]{2,4}\/[a-zA-Z0-9\/_.?=&;]*/){ |match| "<a href='#{match}' target='\_blank'>#{match}</a>"
Gem::Specification.new do |s|
s.name = 'sample'
s.version = '0.1.1'
s.date = '2013-03-19'
s.summary = "Sample gemspec file"
s.description = "A sample gemspec file I use to explain about installing executable files"
s.authors = ["Harisankar P S"]
s.email = ['mailme@hsps.in']
s.files = [
"bin/am_here"]
require 'resolv'
class MxRecordValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
mail_servers = Resolv::DNS.open.getresources(value.split('@')[1], Resolv::DNS::Resource::IN::MX)
if mail_servers.empty? then
record.errors[attribute] << "Does not have a MX record assosiated with mail id"
end
end
end
@coderhs
coderhs / install.sh
Created May 14, 2013 00:24
Ruby Ubuntu installation instructions.
sudo apt-get install ruby1.9.1 ruby1.9.1-dev \
rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 \
build-essential
#install sqlite3
sudo apt-get install libsqlite3-dev
#to test if the installation process went smoothly
#type the following commadn
<?php
/* *** WHMCS JSON API Sample Code *** */
$url = "localhost/order/includes/api.php"; # URL to WHMCS API file goes here
$username = "user"; # Admin username goes here
$password = "passs"; # Admin password goes here
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
@coderhs
coderhs / setting.rb
Last active December 20, 2015 21:49
Conversion using marshaling and JSON load
# To store the application settings in a key value pair
# Type will store the data type so that the conversion can be
# done within the model before send
class Temp
include DataMapper::Resource
# Primary (serial) key
property :id, Serial
loop do
time.sleep
# run the code
end
@coderhs
coderhs / bind.rb
Created September 23, 2013 08:53
Code to get sid and rid from BOSH service of a jabber server. (Server being used here is prosody )
require 'xmpp4r/httpbinding/client'
@client = Jabber::HTTPBinding::Client.new("ruby@example.com")
@client.connect("http://example.com/http-bind")
@client.auth("password")
sid = @client.instance_variable_get("@http_sid")
rid = @client.instance_variable_get("@http_rid")
puts sid
$("#snippet_snippet").click ->
$("#snippet_info").show('slow')