We often write HTML tags with both lower-case and capital letters. As a result, the website’s source code looks ugly. Your task is to write a program which will turn all the lowe-case letters in the HTML tags (i.e. those appearing in between of the signs “<” a “>”) into capital letters.
Input
You are given a fragment of HTML source code.
Output
Your output should print the same HTML source code, but with all the HTML tags written in capital letters.
import fileinput
for line in fileinput.input():
res = '';
for c in line:
if(c == '< '):
flag = True
elif(c == '>'):
flag = False
if(flag == False):
res += c
elif(flag == True):
res += c.upper()
print res
Converting a number from any base to any base.
Assume that n ≤ 36 and the digits are 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z.
Input
The first line contains integer N, the number of test cases. n s r
n is the number to convert
s is the source base
r is the resulting base
import sys
digits ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def base2base(number,rBase,sBase):
'''
# Implementation of Any base to Decimal, but int() is faster
dec = 0
for n in number:
dec = digits.index(n,0,rBase) + dec * rBase
'''
dec = int(number,rBase)
result = []
while(dec != 0):
dec,mod = divmod(dec, sBase)
result.insert(0,digits[mod])
for i in result:
sys.stdout.write( "%s" % (i))
print
instances = int(raw_input())
for v in range(0,instances):
data = raw_input().split(" ")
number = data[0]
rBase = int(data[1])
sBase = int(data[2])
if(number != '0'):
base2base(number,rBase,sBase)
else:
print 0
HTTP Handlers
They are used to process individual endpoints.
Only one handler per request is used
Can be both asynchronous or synchronous
Earliest possible point where you have access to requests
HTTPHandlers are extension based. This means that for every extension .aspx .html etc there is a handler (some share handler).
The example used here is very simple and does nothing special except for displaying some static text. The reason is that ideally before attempting to do something elaborate one should check if it works by doing something simple especially while learning.
The examples here were created in ASP.MVC5 applications. The extension that is used is .kk
SynchronousHTTP Handler
The Solution name is HTTP_Handler
Step 1:
Ignore routing for .kk extension in App_Start/RouteConfig.cs (The reason is that we do not want MVC to try to interpret this file)
routes.IgnoreRoute("{file}.kk");
Step 2:
We create the class that will be our handler at the top level since this is an example and name it CustomHandler.cs
This can be achieved by inheriting IHttpHandler or by using IHttpHandlerFactory (The example uses IHttpHandler)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace HTTP_Handler
{
public class CustomHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
Response.Write("test");
}
public bool IsReusable
{
get { return true; }
}
}
}
Step 3:
We configure the application to use the handler (Integrated mode).
add hello.kk to the link and load it should print test on screen.
Asynchronous HTTP Handler
The Solution name is HTTP_Async_Handler
Step 1:
Ignore routing for .kk extension in App_Start/RouteConfig.cs (The reason is that we do not want MVC to try to interpret this file)
routes.IgnoreRoute("{file}.kk");
Step 2:
We create the class that will be our handler at the top level since this is an example and name it CustomHandler.cs
This can be achieved by inheriting IHttpAsyncHandler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace HTTP_Async_Handler
{
public class CustomHandler:IHttpAsyncHandler
{
// Long Process
private static void generateNumbers(HttpContext context)
{
string s = "";
for (int i = 0; i < 1000; i++)
{
s = s + ' ' + i.ToString();
}
context.Response.Write(s);
}
public static Action<HttpContext> _Handle = generateNumbers;
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
context.Response.Write("BeginProcessRequest Executed");
return _Handle.BeginInvoke(context,cb,extraData);
}
public void EndProcessRequest(IAsyncResult result)
{
// Clean up code here
}
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("ProcessRequest Executed Will not execute");
}
}
}
Step 3:
We configure the application to use the handler (Integrated mode).
As the title says this post describes how to send SMS messages from GO mobile website www.go.com.mt/mygo/ programmatically with C#. This is for educational purposes only and I’m not affiliated in any way to GO. Use the contents of this page at your own risk.
Requirements:
GO Mobile phone line
My Go account for the phone line (Free for every GO Mobile phone)
To send an SMS a user first has to login with his mobile number and password as shown in Fig:1
If the login is successful the user is given access to the form in Fig:2 that takes recipients and a maximum of 420 characters in an SMS. When finished typing the desired SMS click send SMS button.
How to achieve the above programmatically?
To send an SMS there are needed two POSTs, one for Login and the other for the actual SMS to be sent. So a method for sending a POST over HTTPS was created.
Post_data – is the actual data that post will carry
Referrer – is the previous url the post request originated.
cookieC –keeps the cookie the Web Server sends to the browser to maintain the Session state. This is so that to keep the program logged to your My Go account between login and sending a SMS message.
To make sure the Web Server sends the same HTML code that it sends to the Web Browser, the UserAgent is spoofed to the same as the Web Browser used in this case FireFox 5.
Note: the HTML code was cleared from irrelevant tags for clarity. The tags removed include table for formatting and client side validation on the form data.
From the HTML code at https://www.go.com.mt/mygo/ we investigate the login form.
Development becomes easier with the use of Temper Data which empowers the developer to pause and inspect requests and their content. With some manual SMSes testing the query string was figured out.
The code was tested in Visual Studio 2010 in a Console Application the Target Framework was changed to .NET Framework 4 as shown in Fig:3 so as to be able to include the reference to System.Web shown in fig:4.
Make sure the following name spaces are included
using System.Text;
using System.Net;
using System.IO;
Final note
If multiple SMS are to be sent, one could separate login from sending SMS but keep in mind that the session times out after being idle for some time.
What is not included:
Error Handling.
Message Templates.
An explanation of how to send to multiple recipients. This is left for the reader to try out. (probably just separate the numbers with coma)
How to access and retrieve My Go phone book and how to add entries to it programmatically.
Between login and sending an SMS from the website a real web browser sends some GET/POST requests for autocomplete mobile numbers in the phonebook stored in the account. These are skipped entirely.
Does not cater beyond the 8 free daily SMSes that require confirmation from the user to charge the account for the SMS.