|
|
Now the site http://www.sorescu.eu/ offers a search functionality in the left bar.
The code is relatively simple, with two components:
Preparation of the area where the search GUI will be placed:
<p class="ui-state-default ui-corner-all ui-helper-clearfix" style="padding:4px 4px 4px 20px; position:relative">
<span class="ui-icon ui-icon-search" style="position:absolute; left:2px; top:10px"></span>
<input class='ui-corner-all ui-helper-clearfix' style='width:100%' onkeyup='showTopStories(this.value)'/>
<script>
function showTopStories(value){
$('#StoriesSearchList').load('/article/StoriesSearchList/'+encodeURIComponent(value)+' #result', function(){
$('#StoriesSearchList .dms-accordion').accordion().accordion('option','collapsible','true');
});
}
</script>
<p id='StoriesSearchList'>
</p>
</p>
The server-side search module (inside the article.psp):
<p class="ui-state-default ui-corner-all ui-helper-clearfix" style="padding:4px 4px 4px 20px; position:relative">
<span class="ui-icon ui-icon-search" style="position:absolute; left:2px; top:10px"></span>
<input class='ui-corner-all ui-helper-clearfix' style='width:100%' onkeyup='showTopStories(this.value)'/>
<script>
function showTopStories(value){
$('#StoriesSearchList').load('/article/StoriesSearchList/'+encodeURIComponent(value)+' #result', function(){
$('#StoriesSearchList .dms-accordion').accordion().accordion('option','collapsible','true');
});
}
</script>
<p id='StoriesSearchList'>
</p>
</p>
Notes:
- the PSP is a wrapper syntax on top of PHP;
- after loading data, the client is responsible with formatting with JQuery the result;
- in case of fast typing it is possible that multiple distinct requests to come in a different order (I shall fix it by adding a counter logic in few minutes).
Another small challenge; one guy came to me with 550 photographs in around 110 folders (they represent a tree structure of content images to be delivered and browsed by a front-end web application).
The challenge was to compress and resize all the images to improve the browsing performance.
Below is the code I wrote to perform this task: import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImageResize {
static int MAX_SIZE = 150;
public static void main(String[] args) throws IOException {
processFile(new File("C:\\Users\\DragosMateiS\\Desktop\\products"));
}
private static void processFile(File file) throws IOException {
if (file.isDirectory()) {
for (File child : file.listFiles())
if (child.getName().charAt(0) != '.')
processFile(child);
} else if (file.isFile()) {
BufferedImage image=ImageIO.read(file);
if (image == null)
return;
int width=image.getWidth();
int height=image.getHeight();
if(width>height){
height=MAX_SIZE*height/width;
width=MAX_SIZE;
}else{
width=MAX_SIZE*width/height;
height=MAX_SIZE;
}
BufferedImage resized = new BufferedImage(width, height, image
.getType());
Graphics2D g = resized.createGraphics();
g.drawImage(image, 0, 0, width, height, null);
g.dispose();
ImageIO.write(resized, "JPG", file);
}
}
}
My inspiration was
http://www.mkyong.com/java/how-to-resize-an-image-in-java/ with the following small and compact code: BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose(); .
My wife, the user of the Screen Capture application as described in
http://www.sorescu.eu/article/120220221500/Free-Screen-Capture-application explained me that she needs to run it also while in Full Screen mode.
For this I had to hook to the Windows Hot Key events, after I registered with the desired shortcut.
The chosen shortcut is <CTRL>+<ALT>+<PRINT_SCREEN>, and the code update is as following:
#region Hot Key
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd,int id,uint fsModifiers,int vk);
public const int WM_HOTKEY=0x0312;
public const int MOD_ALT=0x0001;
public const int MOD_CONTROL=0x0002;
public const int MOD_NOREPEAT=0x4000;
public const int MOD_SHIFT=0x0004;
public const int MOD_WIN=0x0008;
[DllImport("user32")]
public static extern
bool GetMessage(ref Message lpMsg,IntPtr handle,uint mMsgFilterInMain,uint mMsgFilterMax);
public static void ProcessHotKey() {
uint modifiers=MOD_CONTROL|MOD_ALT;
int key=(int)Keys.PrintScreen;
int hashCode=("hash-"+modifiers+"-"+key).GetHashCode();
if(!RegisterHotKey(IntPtr.Zero,hashCode,modifiers,key))
throw new Exception("Key not registered");
System.Windows.Forms.Message msg=new System.Windows.Forms.Message();
while(GetMessage(ref msg,IntPtr.Zero,0,0))
if(msg.Msg==WM_HOTKEY)
CaptureImage();
}
#endregion with main call as following:
Thread t=new Thread(new ThreadStart(ProcessHotKey));
t.IsBackground=true;
t.Start();Worthy mentioning are the following:
- I used
GetMessage(ref msg,IntPtr.Zero,0,0) for avoiding message queues to any form, but to the current thread; - It was required
int hashCode=("hash-"+modifiers+"-"+key).GetHashCode(); to ensure that the Hot Key is unique in Windows; - The Hot Key handler had to be ran in a separate thread, using
new Thread(new ThreadStart(ProcessHotKey))
My sources of inspiration were:
Somebody requested me to generate a web page with a wall background that should change the wall colour based on the user's desire.
I thought a transparency-enabled background will suffice, with a dynamic background of the image.
Steps:
- Take the background image from my customer;
- Generate a mask image as a copy of the background image, and remove the area (set it to black) where I want to have transparency;
- Run the Java program that is written below;
- Use the final result image and put it in a web page.
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImageTransparency {
private static BufferedImage original;
private static BufferedImage mask;
private static BufferedImage result;
public static void main(String[] args) throws IOException {
String folder = "C:\\Users\\DragosMateiS\\Desktop\\";
original = ImageIO.read(new File(folder + "wall test image.jpg"));
mask = ImageIO.read(new File(folder + "wall test image - mask.jpg"));
result = new BufferedImage(original.getWidth(), original.getHeight(),
BufferedImage.TYPE_INT_ARGB);
process();
ImageIO.write(result, "png", new File(folder
+ "wall test image - result.png"));
}
private static void process() {
int width = original.getWidth();
int height = original.getHeight();
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++) {
Color originalRGB = new Color(original.getRGB(x, y));
Color maskRGB = new Color(mask.getRGB(x, y));
int argb = originalRGB.getRGB();
int r = maskRGB.getRed();
int g = maskRGB.getGreen();
int b = maskRGB.getBlue();
int balance = r * 2 + b + g * 4;
int alpha=balance/7;
if (alpha >= 30)
argb &= 0x00ffffff + (alpha << 24);
result.setRGB(x, y, argb);
}
}
}
Seldom I was in need to perform client filtering on tables and other data, and eventually save the filter. One solution was sending the filter to the server and generate the filtered page.
The functions below (I am using them few years already in Internet Explorer) are used to store and get the properties from fragments.
Some useful clues:
- When the page is loaded, check all the fragment parameters and update the controls and perform filtering, etc.;
- Whenever you update a filter in a text field, etc., you can save it in the fragment;
- You can send the link with fragment to anybody else, and if the first bullet (filter executed on page loading) is accomplished, the URL receiver will see the same page as you.
function getFragmentValues(){
var args=document.location.hash;
if(args)
args=args.split("#")[1].split(",");
else args=[];
var results={};
for(var i=0;i<args.length;i++){
var kv=args[i].split("=");
var k=unescape(kv.shift());
results[k]=unescape(kv.join("="));
}
return results;
}
function getFragmentValue(name,defaultValue){
var result=getFragmentValues()[name];
if(result==null)
result=defaultValue;
return result;
}
function setFragmentValue(name,value){
var values=getFragmentValues();
values[name]=value;
var result=[];
for(var l in values)
if(values[l]!='')
result.push(escape(l)+'='+escape(values[l]));
document.location.hash=result.join(",");
}
As I started to develop small applications in C#, I thought why shouldn't I use the same paradigms that I used in Java... dynamic code execution, execution without compile/build/deploy process, hot-swap, etc.
I am far away from acomplishing the same functionality, but I started with writing a small program (81 lines) mentioned below.
When executing, it is able to compile and execute C# code that is written in text files, on the spot.
The mechanism is quite simple: it expects in the command line the name of an XML file (mentioned below this script) that describes: - the list of CS files that should be compiled;
- the list of external binaries, if required;
- the title of the application;
- the entry point (the class name that contains the Main function).
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Xml;
using System.Xml.XPath;
namespace CSScript {
static class CSScript {
static void Fatal(string message) {
Console.WriteLine("FATAL: "+message);
Console.ReadKey();
Environment.Exit(1);
}
static private XPathNavigator config;
[STAThread]
static void Main(string[] args) {
try {
if(args.Length<1)
Fatal("Usage: CSScript <csscript_file> [<params>]");
if(!System.IO.File.Exists(args[0]))
Fatal("e1204141741 - File '"+args[0]+"' does not exist");
XmlDocument configXml=new XmlDocument();
configXml.Load(args[0]);
config=configXml.CreateNavigator();
if(config.Select("CSScript/EntryClass").Count!=1)
Fatal("'EntryClass' must be one and only one");
if(config.Select("CSScript/Title").Count!=1)
Fatal("'Title' must be one and only one");
Assembly compiledScript=CompileCode();
var title=config.SelectSingleNode("CSScript/Title");
Console.WriteLine("Starting application '{0}'",title);
Console.Title=title.ToString();
string[] parameters=new string[args.Length-1];
for(var i=1;i<args.Length;i++)
parameters[i-1]=args[i];
if(compiledScript==null)
Fatal("e1204141028 - Application not compiled properly.");
var entryClass=config.SelectSingleNode("CSScript/EntryClass").ToString();
Type mainType=getMainType(compiledScript,entryClass);
if(mainType==null)
Fatal("e1204141029 - Type "+entryClass+" could not be found");
var mainMethod=mainType.GetMethod("Main");
if(mainMethod==null)
Fatal("e1204141030 - Main Method 'Main' not found in class "+entryClass);
mainMethod.Invoke(null,new string[][] { parameters });
Console.Write("Press any key to exit...");
Console.ReadKey();
} catch(Exception e) {
Fatal("e1204141747 - "+e.ToString());
}
}
static Assembly CompileCode() {
Microsoft.CSharp.CSharpCodeProvider csProvider=new Microsoft.CSharp.CSharpCodeProvider();
CompilerParameters options=new CompilerParameters();
options.GenerateExecutable=false;
options.GenerateInMemory=true;
options.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
foreach(var assembly in config.Select("CSScript/ReferencedAssemblies/File"))
options.ReferencedAssemblies.Add(assembly.ToString());
var sources=config.Select("CSScript/CSSources/File");
string[]files=new string[sources.Count];
for(int i=0;i<files.Length;i++) {
sources.MoveNext();
files[i]=sources.Current.ToString();
}
CompilerResults results=csProvider.CompileAssemblyFromFile(options,files);
if(results.Errors.HasErrors||results.Errors.HasWarnings)
foreach(CompilerError error in results.Errors)
Console.WriteLine("COMPILATION "+(error.IsWarning?"WARNING":"ERROR")+": "+error.ToString()+": "+error.FileName+":"+error.Line+"@"+error.Column);
if(results.Errors.HasErrors)
Fatal("e1204141031 - Execution aborted, compilation generated errors!");
return results.CompiledAssembly;
}
static Type getMainType(Assembly script,string typeFullName) {
foreach(Type exportedType in script.GetExportedTypes())
if(exportedType.FullName==typeFullName)
return exportedType;
return null;
}
}
}
An example (SMTPServer.csscript) of the input XML looks like:
<CSScript>
<!-- this title should appear in the window's titlebar -->
<Title>SMTPServer</Title>
<!-- list of referenced assemblies - path might require updates for various computers -->
<ReferencedAssemblies>
<File>c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll</File>
<File>c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.XML.dll</File>
</ReferencedAssemblies>
<!-- Entry class in syntax <namespace>.<class name> -->
<!-- This class is expected to contain a Main method -->
<EntryClass>SMTPServer.SMTPServer</EntryClass>
<!-- The list of CS source files, relative to the application -->
<CSSources>
<File>csSources\Listener.cs</File>
<File>csSources\MXDiscovery.cs</File>
<File>csSources\Sender.cs</File>
<File>csSources\SMTP.cs</File>
<File>csSources\SMTPServer.cs</File>
</CSSources>
</CSScript>
Useful information:
- the class mentioned in the CSScript/EntryClass node must have a Main(string[]args) method;
- the Main method must be public and static!
- additional parameters to be sent to the Main method are added to the executed command line!
Example of using the script:
CSScript.exe SMTPServer.csscript listener-ip=0.0.0.0 listener-port=25
In my development (that I started yesterday evening) I used some information from the following links:
The application code is straight forward, and I don't think any comment is required. If you need any comment, then either you should learn programming, or study a bit some C-like languages.
If you wonder why I don't also give the EXE file, please feel free to open the Visual Studio, create an empty project, add a class and paste this code.
One of my last tasks is to build clear requirements based on customer WinWord documents; I also do have a strong feeling that the documentation will change in time, and it will be a dirty work to trace it.
As a consequence, I wrote a small utility to render to the browser the contents (not rendition) of a diven DOCX file:
<?<http.tmcz.index>?>
<hr/>
<link rel="shortcut icon" href="/favicon.ico">
<script type='text/javascript' src='/js/runtime.js'></script>
<link rel="stylesheet" type="text/css" href="/index.css" />
<select onchange='window.location.href="<?=this.classUrl?>/"+this.value+"/"'>
<option></option>
<?var f=new java.io.File('j:\\amdocs\\TMCZ\\1204091520\\Docs\\').list();
var fileNames=[];
for(var i=0;i<f.length;i++)
if((''+f[i]).indexOf('.docx')>=0)
fileNames.push(''+f[i]);
fileNames.sort(function(a,b){return a<b;});
for(var i=0;i<fileNames.length;i++){?>
<option value='<?&fileNames[i]?>' <?=(fileNames[i]==$_ARGS[0])?'selected':''?>>
<?&fileNames[i].split(".docx").join("")?>
</option>
<?}?>
</select>
<hr/>
<?
if(!$_ARGS[0])
return;
var zipFile=new java.util.zip.ZipFile('j:\\amdocs\\TMCZ\\1204091520\\Docs\\'+$_ARGS[0]);
var docXml=zipFile.getInputStream(zipFile.getEntry('word/document.xml'));
var xslis=new java.io.FileInputStream("j:\\http\\tmcz\\docx2struct.xsl");
var bytes=new dms.xml.XSLT(xslis).transform(docXml);
xslis.close();
docXml.close();
var result=new java.lang.String(bytes);
?>
<?=result?>
And the transformation (in incipient phase) is:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" mc:ignorable="w14 wp14">
<xsl:output method="html" version="4.0" encoding="utf-8" indent="no" omit-xml-declaration="no"></xsl:output>
<xsl:template match="/">
<style>
*{font-family: "Arial Unicode MS"}
.Heading1{
border:solid #333333 1px;
border-left:solid #bbbbbb 1em;
background:#bbbbbb;
font-weight:bold;
font-size:1.1em
}
.Heading2{
border:solid #333333 1px;
border-left:solid #bbbbbb 2em;
background:#dddddd;
font-weight:bold;
font-size:1.1em
}
.Heading3{
border:solid #333333 1px;
border-left:solid #bbbbbb 3em;
background:#eeeeee;
}
.Heading4{
border:solid #333333 1px;
border-left:solid #bbbbbb 4em;
background:#eeeeee;
}
.Bullet1square, .Bullet1round{
border-left:solid #bbbbbb 2em;
}
.Bullet2square, .Bullet2round{
border-left:solid #bbbbbb 4em;
}
</style>
<xsl:apply-templates select="node() | @*">
</xsl:apply-templates></xsl:template>
<xsl:template match="w:t"><xsl:value-of select="node()"></xsl:value-of></xsl:template>
<xsl:template match="w:p">
<xsl:element name="p">
<xsl:attribute name="class">
<xsl:value-of select="./w:pPr/w:pStyle/@w:val">
</xsl:value-of></xsl:attribute>
<xsl:apply-templates select="node() | @*">
</xsl:apply-templates></xsl:element>
</xsl:template>
<xsl:template match="w:tbl"><xsl:apply-templates select="node() | @*"></xsl:apply-templates><table border="1"></table></xsl:template>
<xsl:template match="w:tr"><xsl:apply-templates select="node() | @*"></xsl:apply-templates></xsl:template>
<xsl:template match="w:tc"><xsl:apply-templates select="node() | @*"></xsl:apply-templates></xsl:template>
<xsl:template match="w:sectPr"><hr></xsl:template>
<xsl:template match="w:tab"><tab></tab></xsl:template>
<xsl:template match="w:drawing"></xsl:template>
<xsl:template match="w:pict"></xsl:template>
<xsl:template match="node() | @*"><xsl:apply-templates select="node()"></xsl:apply-templates></xsl:template>
</xsl:stylesheet>
My mail server (developed in .NET) is running on IP 188.240.44.77. I used to send and receive mails, everything is fine. However, there is a domain (let's say anonymousdomain.com) where everytime I try to send an email I get the error below:
550 5.7.1 Mail from 188.240.44.77 blocked using Trend Micro RBL+. Please see http://www.mail-abuse.com/cgi-bin/lookup?ip_address=188.240.44.77
Fine, I understand, and I do remember I tried to test my outgoing SMTP connections with another email address hosted on anonymousdomain.com. At the same time I noticed that the Google servers were delivering just fine my mails, without any issues.
I do acknowledge my actions were not ethical, moral, maybe not even legal to do in some countries (running mail tests on other people's addresses).
As a step forward, I shall contact the Trend Microsystems http://www.mail-abuse.com team to inform them that those mails were legitimate and for testing purposes, hoping I shall be removed from the black list.
http://static.sorescu.eu/Applications/WebProxySwitcher-1203280028/WebProxySwitcher.exe
During this time I faced the need to switch between various proxy switches on my computers and laptops. Hotels with specific proxies, public spaces without proxy, work network specific settings, etc.
At the end it became quite annoying to switch proxies between sessions, etc., getting disconnected from work VPNs, hanging between proxies while roaming between my work desk and public places.
And all this must come to an end... hence, I wrote a small Proxy switcher, which simply can to one of the following settings:
- disable the proxy;
- set the proxy to a prespecified value;
- proxy management:
- Add proxy authority with description;
- Edit/add proxy based on a pre-existing setting;
- Delete a proxy setting
As of now I tested the proxy on my Windows 7 with DOT NET 4; further on I shall continue testing this application also on other platforms.
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using Microsoft.Win32;
namespace WebProxySwitcher {
public class WebProxySwitcher:Form {
static RegistryKey registry=Registry.CurrentUser.OpenSubKey("Software",true).CreateSubKey("sorescu.eu").CreateSubKey("WebProxySwitcher");
static RegistryKey ieProxy=Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",true);
[STAThread]
public static void Main() {
Application.Run(new WebProxySwitcher());
}
private NotifyIcon trayIcon;
private ContextMenu trayMenu=null;
public WebProxySwitcher() {
trayMenu=new ContextMenu();
trayIcon=new NotifyIcon();
trayIcon.Icon=Icon.FromHandle(Resources.lightning.GetHicon());
trayIcon.ContextMenu=trayMenu;
trayIcon.Visible=true;
reloadMenu();
}
protected override void OnLoad(EventArgs e) {
Visible=false;
ShowInTaskbar=false;
base.OnLoad(e);
}
public void reloadMenu() {
MenuItem deleteItems=new MenuItem("Delete Proxy");
MenuItem editItems=new MenuItem("Edit Proxy");
trayMenu.MenuItems.Clear();
trayMenu.MenuItems.Add("Add proxy...",OnAddProxy);
trayMenu.MenuItems.Add(deleteItems);
trayMenu.MenuItems.Add(editItems);
trayMenu.MenuItems.Add("Disable proxy",OnClearProxy);
trayMenu.MenuItems.Add("-");
foreach(string key in registry.GetValueNames()){
trayMenu.MenuItems.Add(key,OnSwitchProxy);
deleteItems.MenuItems.Add(key,OnDeleteProxy);
editItems.MenuItems.Add(key,OnEditProxy);
}
trayMenu.MenuItems.Add("-");
trayMenu.MenuItems.Add("Exit Proxy Switcher by www.sorescu.eu",OnExit);
var proxyEnabled=ieProxy.GetValue("ProxyEnable");
var location=ieProxy.GetValue("ProxyServer");
var message="Web proxy disabled.";
if((int)proxyEnabled==1)
message="Proxy set to "+location;
trayIcon.BalloonTipTitle=message;
trayIcon.BalloonTipText="Web Proxy Switcher by \nhttp://dragos-matei.sorescu.eu";
message+=" \n"+trayIcon.BalloonTipText;
trayIcon.Text=message.Substring(0,63);
trayIcon.ShowBalloonTip(2000);
}
public void OnAddProxy(object sender,EventArgs e) {
string proxy=Interaction.InputBox("<host>[:<port>] (eg. localhost, localhost:8080); <blank> for abort:","Step 1/2 - Proxy authority","");
if(proxy=="")return;
string key=Interaction.InputBox("Description (title) of the proxy:","Step 2/2 - Proxy description","");
registry.SetValue(key,proxy);
reloadMenu();
}
public void OnDeleteProxy(object sender,EventArgs e) {
MenuItem item=sender as MenuItem;
string proxy=""+registry.GetValue(item.Text);
MsgBoxResult result=Interaction.MsgBox("Are you sure you want to delete "+proxy+" ("+item.Text+")?",MsgBoxStyle.YesNo);
if(result==MsgBoxResult.Yes) {
registry.DeleteValue(item.Text);
reloadMenu();
}
}
public void OnEditProxy(object sender,EventArgs e) {
MenuItem item=sender as MenuItem;
string proxy=""+registry.GetValue(item.Text);
string key=item.Text;
proxy=Interaction.InputBox("<host>[:<port>] (eg. localhost, localhost:8080); <blank> for abort:","Step 1/2 - Proxy authority",proxy);
key=Interaction.InputBox("New description (title) of the proxy"+proxy+":","Step 1/1 - Proxy description change",key);
registry.SetValue(key,proxy);
reloadMenu();
}
public void OnClearProxy(object sender,EventArgs e) {
ieProxy.SetValue("ProxyEnable",0);
}
public void OnSwitchProxy(object sender,EventArgs e) {
MenuItem item=sender as MenuItem;
string proxy=""+registry.GetValue(item.Text);
ieProxy.SetValue("ProxyEnable",1);
ieProxy.SetValue("ProxyServer",proxy);
reloadMenu();
}
private void OnExit(object sender,EventArgs e) {
this.Dispose();
Application.Exit();
}
protected override void Dispose(bool isDisposing) {
if(isDisposing)
trayIcon.Dispose();
base.Dispose(isDisposing);
}
private void InitializeComponent() {
this.SuspendLayout();
this.ClientSize = new System.Drawing.Size(500, 293);
this.MinimizeBox = false;
this.Name = "WebProxySwitcher";
this.ShowIcon = false;
this.Text = "Web Browser Proxy Switcher";
this.ResumeLayout(false);
}
}
}
The application can be found at http://static.sorescu.eu/Applications/WebProxySwitcher-1203280028/WebProxySwitcher.exe.
I got the following message:
010011000110000100100000011011010111010101101100011101000110100100100000011000010110111001101001001011000010000001101101011010010111001101110100011001010111001000100000010001000110010101111000011101000110010101110010001000000011101000101001
from a guy that sometimes likes challenging people with unusual quests.
In few minutes I replied with 01001101011101010110110001110100011101010110110101100101011100110110001100101100001000000110001101110101001000000111000001101100011000010110001101100101011100100110010100101110001000000011101000101001
I hope I put the proper values at the proper place.
Are you curious what does it mean?
import java.io.IOException;
public class DecryptSecretMessage{
public static void main(String[] args) throws IOException {
encode();
decode();
}
public static void encode(){
String text="Multumesc, cu placere. :)";
String result="";
for(int i=0;i<text.length();i++){
int c=text.codePointAt(i);
for(int j=0;j<8;j++){
result+=(c>>(7-j))%2;
}
}
System.out.println(result);
}
public static void decode(){
String source="010011000110000100100000011011010111010101101100011101000110100100100000011000010110111001101001001011000010000001101101011010010111001101110100011001010111001000100000010001000110010101111000011101000110010101110010001000000011101000101001";
byte[]data=new byte[source.length()/8];
for(int pos=0;pos<data.length;pos++){
for(int bit=0;bit<8;bit++)
data[pos]=(byte) (data[pos]*2+source.codePointAt(pos*8+bit)%2);
}
System.out.println(new String(data));
}
}
|