|
I have been working hard on a .NET project for work and thus have not had the energy to do any other work. The project is nearing a major milestone in the next few months which should means I should be less stressed. Which means I can start working on IDT related stuff. So, stay tuned or something.
posted by dharh 12:47 PM Jul 20th via idt
8. Open a text file and convert it into HTML file. (File operations/Strings)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace lrn2csharp8
{
class Program
{
static void Main( string[ ] args )
{
string file = "";
string html = "<html><head><title></title></head><body>{0}</body></htm>";
string textFile = "";
Console.WriteLine( "Input name of a file in the current directory to convert into an HTML document." );
Console.Write( ":" );
try
{
file = Console.ReadLine( );
FileStream fs = new FileStream( file, FileMode.Open, FileAccess.Read );
StreamReader sr = new StreamReader( fs );
while(!sr.EndOfStream)
{
string line = sr.ReadLine( );
if ( line.Length != 0 )
textFile += "<p>" + line + "</p>";
}
sr.Close( );
StreamWriter sw = new StreamWriter( fs.Name + ".html" );
sw.Write( string.Format( html, textFile ) );
sw.Close( );
}
catch ( Exception e )
{
Console.WriteLine( "WTF?!?" );
}
}
}
}
posted by dharh 2:14 AM Jan 30th, 2010 via idt
Chrome Extensions are here! Since Chrome became my main browser there's one thing I've missed the most and thats the extensive extension library on Firefox. Now that we finally have extensions here's a short list of the ones I am using so far:
That's it for now. I'll add more as I find good ones. posted by dharh 2:40 PM Dec 8th, 2009 via idt
7. Printing output in different formats (say rounding up to 5 decimal places, truncating after 4 decimal places, padding zeros to the right and left, right and left justification)(Input output operations)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lrn2csharp7
{
class Program
{
static void Main( string[ ] args )
{
double theNumber;
Console.WriteLine( "Input a number to be formatted" );
Console.Write( ":" );
try
{
theNumber = Convert.ToDouble( Console.ReadLine( ) );
Console.WriteLine( "Original number: {0}", theNumber );
Console.WriteLine( "Rounded up to the 5th decimal place: {0}", Math.Round( theNumber, 5 ) );
Console.WriteLine( "Truncating after the 4th decimal place: {0}", Decimal.Truncate( Convert.ToDecimal( theNumber * 10000 ) ) / 10000 );
Console.WriteLine( "Padding 7 zeroes on each side: {0}", String.Format( "{0:0000000.0000000}", theNumber ) );
Console.WriteLine( "Here is a box with 20 spaces: | |" );
Console.WriteLine( "Here is the number left justified: |{0,-20}|", theNumber );
Console.WriteLine( "Here is the number right justified: |{0,20}|", theNumber );
}
catch ( FormatException fe )
{
Console.WriteLine( "You did not enter a valid number fool." );
}
}
}
}
posted by dharh 9:56 PM Dec 5th, 2009 via idt
After a really long development time (too long, with 6 months where I didn't even touch the code), neThing v0.7 has been completed and released. You can view the changelog to see the changes.
posted by dharh 5:23 PM Dec 4th, 2009 via idt
In the interest of simplicity I've started work on simplifying the site. After almost two years working with the split dichotomy of article and blog posts I've come to the realization that it is stupid.
First, because this precludes the notion I've had for a while that neThing is meant to be a gateway of streams, where multiple sources, including the stuff generated from the site itself, feed the postMonster (the backend that handles these things). Two, because its too complicated. What makes a blog post different than an article post? In reality nothing except a few bits than can be more than handled with a checkbox or two when creating a post. So, now all posts are posts. They are still identified by where they originated from, such as Twitter, but otherwise blog posts are now fully converted into articles. Which means they have wiki discussion pages and histories. As far as the wiki bot is concerned it is an article and thus can be linked as such by name. Conflicts will arise and thus it will behoove me, and anyone else using neThing in the future, to mark master posts when multiple of them have the same name. The other posts would then use their POSTID as their permalink. Also notice that the left slider menu is gone. Replaced by two much simpler archive boxes on the right side above the twitter panel. There is also an Archive page that can be accessed using the IDT logo menu up top. The first archive box is simple, it displays years, and then gives links to the months that had posts. The second archive box is a cloud of most tags. That's all for now. posted by dharh 5:16 PM Dec 2nd, 2009 via idt
6. Scientific calculator supporting addition, subtraction, multiplication, division, square-root, square, cube, sin, cos, tan, Factorial, inverse, modulus
This is a fairly simple implementation of a console calculator. It only takes 2 number expressions ( ex: 1 + 1 ) as well as / commands for most other functions, except factorial ( n! ). Very little error checking is being done. All sorts of invalid inputs will cause this to throw exceptions. using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lrn2csharp6_console
{
class Program
{
private static String Version = "0.0";
static void Main( string[ ] args )
{
Console.WriteLine( "neSP: Calc v" + Version );
Console.WriteLine( "---------------------------------" );
Console.WriteLine( "Enter Command. ( example: /help )" );
int end = 0;
while ( end == 0 )
{
String exp = "";
Console.Write( ":" );
try
{
exp = Console.ReadLine( );
}
catch ( InvalidOperationException )
{
Console.WriteLine( "Not a valid command." );
exp = "";
}
if ( exp.Length == 0 )
{
// empty command
}
else if ( exp.ToCharArray( ).First( ) == '/' )
{
if ( exp.Split( ' ' ).ToString( )[ 0 ].Equals( "/help" ) )
{
Console.WriteLine( "You are being helped:" );
Console.WriteLine( "/help - bring up this help system." );
Console.WriteLine( "/quit or /q - quit program." );
Console.WriteLine( "/prime n - generate prime numbers from 2 to n." );
Console.WriteLine( "/factor numerator/denominator - factors fraction." );
Console.WriteLine( "/sqrt n - finds the square root of n." );
Console.WriteLine( "/cbrt n - finds the cube root of n." );
Console.WriteLine( "/sin n - finds sine of n." );
Console.WriteLine( "/cos n - finds cosine of n." );
Console.WriteLine( "/tan n - finds tangent of n." );
Console.WriteLine( "/inv numerator/denominator - finds inverse of fraction." );
Console.WriteLine( "n! - finds factorial of n." );
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/quit" ) || exp.Split( ' ' )[ 0 ].Equals( "/q" ) )
{
end = 1;
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/primes" ) )
{
Console.Write( "primes:" );
prime( Convert.ToInt32( exp.Split( ' ' )[ 1 ] ) );
Console.WriteLine( );
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/factor" ) )
{
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/sqrt" ) )
{
Console.WriteLine( Math.Sqrt( Convert.ToDouble( exp.Split( ' ' )[ 1 ] ) ) );
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/cbrt" ) )
{
double power = 1.0 / 3.0;
Console.WriteLine( Math.Pow( Convert.ToDouble( exp.Split( ' ' )[ 1 ] ), power ) );
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/sin" ) )
{
Console.WriteLine( Math.Sin( Convert.ToDouble( exp.Split( ' ' )[ 1 ] ) ) );
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/cos" ) )
{
Console.WriteLine( Math.Cos( Convert.ToDouble( exp.Split( ' ' )[ 1 ] ) ) );
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/tan" ) )
{
Console.WriteLine( Math.Tan( Convert.ToDouble( exp.Split( ' ' )[ 1 ] ) ) );
}
else if ( exp.Split( ' ' )[ 0 ].Equals( "/inv" ) )
{
String fraction = exp.Replace( "/inv ", "" );
double numer = Convert.ToDouble( fraction.Split( '/' )[ 0 ] );
double denom = Convert.ToDouble( fraction.Split( '/' )[ 1 ] );
Console.WriteLine( denom / numer );
}
else
{
Console.WriteLine( "Invalid command ( " + exp + " ) supplied." );
}
}
else if ( exp.Contains( '!' ) )
{
int f = Convert.ToInt32( exp.Split( '!' )[ 0 ] );
Console.WriteLine( f );
int total = 1;
for ( int i = 0; i < f; i++ )
{
total = total * ( i + 1 );
}
Console.WriteLine( total );
}
else
{
calc( exp );
}
}
}
static void calc( String expression )
{
String[ ] stack = expression.Split( ' ' );
Console.WriteLine( doCalc( Convert.ToDouble( stack[ 0 ] ), Convert.ToChar( stack[ 1 ] ), Convert.ToDouble( stack[ 2 ] ) ) );
}
static double doCalc( double left, char theOperator, double right )
{
double total = 0.0;
if ( theOperator == '+' )
{
total = add( left, right );
}
else if ( theOperator == '-' )
{
total = subtract( left, right );
}
else if ( theOperator == '*' )
{
total = multiply( left, right );
}
else if ( theOperator == '/' )
{
total = divide( left, right );
}
else if ( theOperator == '^' )
{
total = Math.Pow( left, right );
}
else if ( theOperator == '%' )
{
total = mod( Convert.ToInt32( left ), Convert.ToInt32( right ) );
}
return total;
}
static double add( double num, double num2 )
{
return ( num + num2 );
}
static double subtract( double num, double num2 )
{
return ( num - num2 );
}
static double multiply( double num, double num2 )
{
return ( num * num2 );
}
static double divide( double num, double num2 )
{
if ( num2 == 0 )
{
Console.WriteLine( "ERROR: Division by zero." );
return num;
}
else
{
return ( num / num2 );
}
}
static int mod( int num, int num2 )
{
return ( num % num2 );
}
static void prime( int num )
{
int count = 0;
for ( int _i = 2; _i < num; _i++ )
{
if ( !isPrime( _i ) )
{
if ( ( count % 10 ) == 0 ) Console.WriteLine( );
Console.Write( " {0,6}", _i );
count++;
}
}
}
static bool isPrime( int num )
{
bool notPrime = false;
for ( int k = num - 1; k > 1 && !notPrime; k-- )
{
if ( num % k == 0 ) notPrime = true;
}
return notPrime;
}
}
}
posted by dharh 8:46 PM Nov 29th, 2009 via idt
« Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Next »
|
airships america attention batteries blogs books browser c++ computers copyright CSharp dharh disaster DIY DRM drugs economy energy environment FCC gaming government history HTML humor idt internet interview java javascript linkjack linux MLP moving music nature neThing neTodo networking news opensource philosophy podcasts politics poverty programming projects radio religion science sick simple software space sparce tagging technology twitter unbirthday video wiki
|

- a little order in the chaos where the mind dwells



