ShareThis

Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Friday, December 28, 2012

Speed up your HTML/CSS with Zen Coding

Here is a video of a new tool available for writing less HTML and getting MORE out of it! The system works by allowing you to enter abbreviations of tags with attributes, even child nodes, and expand them into actual HTML. Looks pretty nifty, definitely going to give this a try.



 You can read more about it and get the download in the Smashing Magazine article.

Friday, September 7, 2012

[Scheme] How to curry a function

This is a new concept on my Scheme homework. The request is to turn a somewhat curried script into a fully-curried script:


(define noncurried?
    (lambda (x y)
       (lambda (z t) 
        (> (+ x y) (+ z t))
       )
    )
)

; In English, this function returns #t if x and y are greater than z and t, or #f if they are less than.
In turning this function into a fully curried function, we need to split up the lambda expressions and add two more, such that, each parameter that is part of the function is defined in its own lambda expression. 

(define curried?
  (lambda (x)
    (lambda (y)
      (lambda (z)
        (lambda (t)
            (> (+ x y) (+ z t))
          )
        )
     )
   )
)

Interesting in how to call curried? 


((((curried? 1) 2) 3) 4)

Monday, August 13, 2012

[java] Is Number in Fibonacci Sequence Code

Found this code on StackOverflow. This is a very simple iterative solution to see if a given long value "n" is a part of the fibonacci sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc...

int isFib (long n)
{
    int pos = 2;
    long last = 1;
    long current = 1;
    long temp;

    while (current < n)
    {
        temp = last;
        last = current;
        current = current + temp;
        pos++;
    }

    if (current == n)
        return pos;
    else
        return 0;
}

Sunday, August 12, 2012

[java] One line Fibonacci Sequence Code!

Here is a cool recursive solution to the fibonacci sequence in one line! However, runtime is O(2^n)... so iterative solution is the better route to take for performance.

int fib(int n){
  return n <= 2 ? 1: fib(n-1) + fib(n-2);
}

Friday, August 3, 2012

You are shrunk to the height of a nickel and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The blades will start moving in 60 seconds. What do you do?

Given that you are a size of a nickel, you won't be able to make much noise and you surely won't be able to escape on your own. If you are stuck inside a blender in the Google office, chances are you probably won't be able to jam the blades before they start turning as it is a very nice Black & Decker model blender.

That really narrows down your options. If you had a grappling hook, you could easily escape. But who carries grappling hooks around waiting to be shrunk and stuck inside a blender? No one.

Lets take a look at the facts:

Blenders do not operate on their own. Maybe the fanciest ones have timers, but that doesn't make much sense to have a blender auto-start. It isn't like coffee. So someone has to be pushing that button to start the blender in 60 seconds. Your best bet is to jump around frantically waving your arms to get their attention before they dump their blender food in on you. Since the blades are probably shiny, and just maybe, the sun is shining in on the room, you may have a chance to run around the blades and the reflection may catch their eye. (shiny to covered and back to shiny). At this point , you engage the individual in a discussion in which you may need to plead for your life if they are a generally apathetic or cynical person. Otherwise you are good to go as far as getting out of the blender. But the problem doesn't stop there. You are the size of a nickel. You must now go home and watch Honey, I Shrunk the Kids! and watch it till the end (Yeah, I know...) to see how the kids get returned to normal size. Follow the same steps in the movie and you will be back to normal. And then you can enact revenge on whoever attempted your murder by miniaturization and death by blender.

This is how I would answer this question.

Joseph

Wednesday, June 20, 2012

Are if statements or switch case faster?

The consensus is that switch / case statements are faster. See the stack overflow question.

Sunday, April 15, 2012

[SOLVED] Target="_blank" on a window.location redirect?


Instead of using
window.location='newUrl'
Try:
window.open('newUrl');

SQL How to delete null records

Most people try something like this:

DELETE FROM tableName
WHERE columnName = NULL


That is wrong! Use this:


DELETE FROM tableName
WHERE columnName IS NULL

You can verify by doing "select * from columnName" to see the updated column.



Friday, April 13, 2012

HTML Input form restrict to numbers only

Here is an awesome script from htmlcodetutorial.com on how to restrict an input textbox to numbers only. View the source here.



<SCRIPT TYPE="text/javascript">
<!--
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

//-->
</SCRIPT>
Now we can create a numbers only field using the onKeyPress attribute. For our first example, we'll create a field which accepts five digits as for a United States ZIP Code. Set the onKeyPress attribute exactly like it is here:
<FORM ACTION="../cgi-bin/mycgi.pl" METHOD=POST>
U.S. ZIP Code: 
  <INPUT NAME="dollar" SIZE=5 MAXLENGTH=5
   onKeyPress="return numbersonly(this, event)">
  <INPUT TYPE=SUBMIT VALUE="go">
</FORM>


Maximum length/lines in a sql text field?

The max legth of text in sql is Variable-length non-Unicode data with a maximum length of 2,147,483,647 characters.

Sunday, April 8, 2012

How to insert multiple records into SQL in one statement

All you need to do is add ";" to the end of each statement. Enter them all in at once and execute ("\g")



If you smacked yourself on the head after reading this.. like this post!

Tuesday, April 3, 2012

new racquetball app coming from evonsdesigns




Monday, April 2, 2012

Android: How to Retrieve Shared Preferences Values

To a beginner this may be daunting. But it is a really easy solution!

Example preference activity:

public class FooActivity extends PreferenceActivity {

 @Override
 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  addPreferencesFromResource(R.xml.preference);
 }
}

Preference xml file:


Method to access those items: (use in any class necessary)


import android.preference.PreferenceManager;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// then you use
prefs.getBoolean("keystring", true);

Set your android:key= "" to the key value you want to access later on. That simple! No need for ids on checkbox preferences either (unless you're doing dynamic changes to the settings and need to)


Sunday, April 1, 2012

How to use Dropbox to sync Android Projects


Hello avid android programmers. If you're like me, you have at least two stations that you program on. A laptop and a desktop pc. In the past you've had some trouble getting android applications to sync between your computers and the workspace on dropbox.

Here is the problem: Workspaces are unique to the computer they are on and the location they are at. So having the same workspace usable from TWO pcs causes them to clash (and subsequently breaks your android builds).

The fix: It is actually really simple. All you need to do is retain the original workspaces on each PC. You dont want to sync the workspace on dropbox (unless only one PC uses it.)

From the secondary pc, or both if you prefer, import the project folder into your eclipse workspace. Do not copy the files into your workspace ( we need them to reference the synced files! ).

You should now be able to run the android emulator and app fine without any startup errors on your secondary device!

Cheers,
Joe


Monday, February 13, 2012

How a Programmer's browser looks after a programming session


This is quite an understatement, too.

Wednesday, February 8, 2012

[C#] Get Extension part of Url


You can split it on .:
string url = "www.abc.com/files.zip";
string lastPart = url.Split(new char[] {'.'}).Last()
lastPart == "zip"

Wednesday, February 1, 2012

C# Website Image Downloader is here! ImageGrabber


After a couple weeks of work… Im proud to pronounce ImageGrabber Free!
Why use it? - It will scour a page for any images and download them for you to the requested filefolder.
- You’ll never have to manually save every image again.
- The ImageGrabber uses an advanced crawler that can crawl an entire domain, or the whole internet!! THE WHOLE INTERNET~~~
How to use it: You select a file folder, then paste your site URL, and select the crawler depth. Then crawl! Watch as your folder populates or the log refreshes with progress!
What is the catch? No catch. ImageGrabber Free will be offered with reduced capability. A pro version will be released later this year that gives users the most customizable experience.
Features that will be in pro: - Crawl ALL –> Every link given in will be processed.
-
File size restrictions. (Set lower / upper bound limits on file sizes to keep)
- FolderSort –> Sort images based on similar names
- StraightToZip –> Sort images based on similar names, then send to Zip files.

Friday, January 13, 2012

USA Capitals and States XML file download

XML file for programming use

Title: USA Capitals and States XML file download
Format: State | Capital | State Nickname

Download:

Monday, January 2, 2012

C# copy to clipboard : how to Copy-Paste to and from clipboard using c#


To make the operations such as copy paste using c#,we have to use the Clipboard Class which provides methods to place data on and retrieve data from the system Clipboard.
Example :-
Copy the text from txtCopy to clipboard
 System.Windows.Forms.Clipboard.SetDataObject(txtCopy.Text, true);
Paste the text from clipboard to txtPaste
IDataObject clipData = Clipboard.GetDataObject();
if (clipData.GetDataPresent(DataFormats.Text))
{
txtPaste.Text = clipData.GetData(DataFormats.Text).ToString();
}
else
{
txtPaste.Text = "Could not retrieve data from the clipboard.";
}