2012-11-28

solution to vagrant up -> "The host class is reporting that NFS is not supported by this host"

got this error running vagrant up:
ajt@ajtNbMint /media/c/ajt/edu/20122/eng100l/github/whwn $ vagrant up
[default] VM already created. Booting if it's not already running...
The host class is reporting that NFS is not supported by this host,
or `nfsd` may not be installed. Please verify that `nfsd` is installed
on your machine, and retry.

in linux, i solved this by opening synaptic package manager and installing "nfs-kernel-server"

too late for me to try now, but i have a feeling that running this in a terminal would work too:
sudo apt-get install nfs-kernel-server

in windows, change the vagrantfile so you use virtualbox's shared folders instead of nfs, by setting nfs=>false:
config.vm.share_folder "blah", "~/blah", ".", :extra => 'dmode=755,fmode=644', :nfs => false

2012-11-15

split "city, state zip" in excel.


here are some formulas to split a cell containing city, state and zip into separate city, state and zip cells in microsoft excel.

format: "city, state zip" e.g. "La Jolla, CA 92092-0100"
  • comma after city name, followed by a space
  • state is two letters, followed by a space
in cell b1, type
=LEFT(A1,(FIND(",",A1))-1)

in cell c1, type
=MID(A1,FIND(",",A1)+2,2)

in cell d1, type
=RIGHT(A1,LEN(A1)-FIND(",",A1)-4)

format: "city, state zip" e.g. "La Jolla, California 92092-0100"
  • comma after city name, followed by space
  • state is specified but of any length and followed by space
in cell b1, type
=LEFT(A1,(FIND(",",A1))-1)

in cell c1, type
=MID(A1,FIND(",",A1)+2,FIND("*", SUBSTITUTE(A1, " ", "*", LEN(A1) - LEN(SUBSTITUTE(A1, " ", ""))))-(FIND(",",A1)+2))

in cell d1, type
=RIGHT(A1, LEN(A1) - FIND("*", SUBSTITUTE(A1, " ", "*", LEN(A1) - LEN(SUBSTITUTE(A1, " ", "")))))

format: "city state zip" e.g. "La Jolla CA 92092-0100"
  • city, state, zip separated by 1 space only
  • state is two letters
in cell b1, type
=LEFT(A1,(FIND("*", SUBSTITUTE(A1, " ", "*", LEN(A1) - LEN(SUBSTITUTE(A1, " ", "")))))-4)

in cell c1, type
=MID(A1,(FIND("*", SUBSTITUTE(A1, " ", "*", LEN(A1) - LEN(SUBSTITUTE(A1, " ", "")))))-2,2)

in cell d1, type
=RIGHT(A1, LEN(A1) - FIND("*", SUBSTITUTE(A1, " ", "*", LEN(A1) - LEN(SUBSTITUTE(A1, " ", "")))))

2012-10-26

run linux mate in sudo mode

i have linux mint with the mate desktop, and i wanted to copy a file into a folder but got "error opening file: permission denied" or "the folder cannot be copied because you do not have permissions to create it in the destination".  i remembered before that i could run mate as root or in sudo mode or something, but i couldn't remember what it was called.  so how do you do administrative tasks in mate?

when you browse the contents of a folder in mate, you are actually seeing the caja app built into mate.  so i will tell you how to run caja as an administrator or "as superuser".

open a terminal, and type "sudo caja".  boom! done.  you can do anything in this window.

if you want to run all of mate apps in administrative mode, you can type "sudo mate-panel".  i'm not sure how you're going to close your first instance of mate-panel so you might be stuck with 2 task bars on top of each other.

2012-10-13

change date and time format of clock applet in linux mint mate

in the mate desktop environment that comes with linux mint, the clock is an applet built into the panel program.

to change the date and time format, press alt+f2 or open a terminal window.  type "mateconf-editor" and press enter.  this opens the configuration editor for mate.  if you don't have this installed, type "apt-get install mate-conf-editor" in a terminal.

navigate to /apps/panel/applets/applet_clock and click on "format".  read the long description and possibly set the value to "custom".  if you use "custom", also change the "custom_format" field, which accepts the same format strings that strftime() uses.

i set custom_format to "%F %H:%M" which displays the time in the format 2012-10-13 15:17

2012-10-06

solution to ImportError: No module named OSRNG

i was trying to run fab bootstrap on my windows machine an received the error: "ImportError: No module named OSRNG"

i found a folder on my computer called C:\PythonX\ that had the package i needed.  i merged the contents of this folder with my python installation in "C:\Program Files (x86)\python27\"

in the end, you need to have a folder like this, but with the location to your python installation:
C:\Program Files (x86)\python27\Lib\site-packages\Crypto\Random\OSRNG

2012-08-27

ucsd single sign-on does not allow saving password

if you go to ucsd and frequently log into sites that use their single sign-on page such as my tritonlink, you must have noticed that their log on page has the username/pid field set as a password field, so it looks like you're logging in with two passwords.  this tricks browsers into thinking you aren't logging in to something but possibly just changing your password, so it doesn't prompt to save your login info.  ucsd thinks they know what's best for you, but if you keep your computer physically secure and always lock your computer (windows key + 'L') before you leave, then why not save your password?

well you can with the help of either keepass password safe (mostly for pc), or lastpass online password manager.

in keepass, you can set up auto-type on an entry.  make a new entry, type your pid (eg A09...) for the username, and type your ucsd password.  the title of the entry should be nothing other than "ucsd".  now hold ctrl+alt+'a' (for "auto") when you're at the single sign-on page.  keepass will see that you're on a window that contains "ucsd" in the title and will automatically type your username, {tab}, your password and {enter}as if you typed it on your keyboard.

if you want to use lastpass, just install their extension for firefox, chrome, safari or even internet explorer.  sign in once and it'll prompt you to save the password -- lastpass is the only one smart enough to ask.

DataRow keeps converting values into strings

when i use DataRow.ItemArray or the DataRow's indexer (eg myDataRow[0] = ...) to set the values to objects, the values are converted to strings.

DataRow row = ...;
row[0] = (object)5;

//problem:
//row[0] == "5"
//row[0] != 5

the solution is to specify the type on the DataTable's column.

DataTable t = ...;
t.Columns[0].DataType = typeof(object);

2012-08-13

easily open csv files as all text fields with vbs send-to

when excel opens csv files, it will try to infer the data types of the cells based on the data in the file.  however, sometimes it gets it wrong. for example with zip codes, it will think they are plain numbers and remove leading 0's.

to open a csv file as text in excel 2007 or 2010, you can click on the data tab and click from text.  the text import wizard will let you click on each column and specify that it should be a text column so excel won't mess with the data.

it's clumsy to use the text import wizard every time you want to open a csv file with all the columns read as text.  my solution was to add an item to the "send-to" menu.  whenever you right click on a file in explorer, there's a "send to" menu, and you can add custom items to this menu.  i added a script that imports the file into excel.



here's how to set it up:

  1. open notepad
  2. paste the script at the bottom
  3. click file / save as...
  4. for the file name, type %userprofile%\AppData\Roaming\Microsoft\Windows\SendTo\openCsvAsText.vbs
  5. click save

now to use it, right click on a csv file, and click "send to" and then click openCsvAsText.vbs

that's it!

note:  the script actually opens the file twice.  first, it uses OpenText to open the csv file like normal.  then, the contents of the sheet is cleared (but the file is not saved).  then it uses the text import wizard to import the same data, but with different parsing options.  this is necessary because neither function does everything:  first, OpenText ignores the FieldInfo parameter when the file extension ends in "csv" -- it only listens when it's a "txt" file.  second, if you just use the text import wizard, then when you go to save the file, it will ask you where to save it like it's a new workbook.  this is because you'd literally be creating a new workbook and importing some data, which is not the same as opening the data directly.  so, we open the data directly, then import on top with the correct settings.

i would love to hear if this helped you.

here's the script:



Option Explicit

Const xlTextFormat = 2
Const xlTextQualifierDoubleQuote = 1
Const xlDelimited = 1
Const xlOverwriteCells = 0


'when using the send-to menu, windows explorer passes the filename of the right-clicked file
'as a command line argument to the application used to open the file in the send-to folder,
'in this case "Microsoft Windows Based Script Host".  this is the program that runs .vbs files.
'this program makes the filename command line argument available to this script via
'WScript.Arguments.Ietm(0).

Dim filename
filename = WScript.Arguments.Item(0)


'we need specify each column individually.  this says that the first 500 (0-499)
'columns should be read as text.  we will use fieldInfo later.

Dim fieldInfo(499)
Dim i
For i = 0 To UBound(fieldInfo)
    fieldInfo(i) = xlTextFormat
Next


'start excel, with no screen updating because it would flicker around
'while opening the file the second time (we read from the file twice
'due to limitations of excel).

Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
'objExcel.ScreenUpdating = False 'optional

'open the file, so when we save it later, it knows where to save

Dim objWorkbook
objExcel.Workbooks.OpenText(filename) '.Add
Set objWorkbook = objExcel.ActiveWorkbook


'clear the contents of the file, because we opened it with all the default (wrong) settings

Dim objWorksheet
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.UsedRange.ClearContents

'set format of *all* cells to text, so when we import, we don't have
'the imported cells as "text" but the rest of them as "general".
objWorksheet.Cells.NumberFormat = "@"

'do the equivalent of using the text import wizard, but change some options:
'-RefreshStyle: overwrite cells instead of making room
'-PreserveFormatting: got rid of it
'-AdjustColumnWidth: set to false

Dim m
Set m = objWorksheet.QueryTables.Add("TEXT;" & filename, objWorksheet.Range("$A$1"))
m.FieldNames = True
m.RowNumbers = False
m.FillAdjacentFormulas = False
m.RefreshOnFileOpen = False
m.RefreshStyle = xlOverwriteCells
m.SavePassword = False
m.SaveData = True
m.AdjustColumnWidth = False
m.RefreshPeriod = 0
m.TextFilePromptOnRefresh = False
m.TextFilePlatform = 65001 'UTF-8. for "OEM United States" use 437
m.TextFileStartRow = 1
m.TextFileParseType = xlDelimited
m.TextFileTextQualifier = xlTextQualifierDoubleQuote
m.TextFileConsecutiveDelimiter = False
m.TextFileTabDelimiter = False
m.TextFileSemicolonDelimiter = False
m.TextFileCommaDelimiter = True
m.TextFileSpaceDelimiter = False
m.TextFileColumnDataTypes = fieldInfo
m.TextFileTrailingMinusNumbers = True
m.Refresh False


'the contents now should be the contents already in the file,
'so marked as saved so it does not prompt to save if no
'changes are made.

objWorkbook.Saved = True


'done.

objExcel.ScreenUpdating = True

2012-08-11

excel macro to re-order / rearrange columns by column name


in excel, you can easily write scripts to reorder and delete columns using just the column names (specified in the header row -- row 1) using the below vba macro i made.

for example, to make a simple macro that delete's the "name" column:

be sure to read the documentation in the comments to learn how to do more.


i'd love you to comment if this helped you or if you need help using the script.

Sub RearrangeColumns()
    If ConfirmFormat Then
    
        '==================================================================
        '
        ' type how you want to rearrange columns below.
        ' here's what you can do:
        '
        ' delete a column
        '    to delete the "site_dir1" column, type
        '    DeleteColumn "site_dir1"
        '
        ' move a column to a location specified by letter
        '    to move "pmt_descrp" to column "A", type
        '    MoveColumn "pmt_descrp", "A"
        '
        ' move a column before another column
        '    to move "pmt_class" before the "site_addrs" column, type
        '    MoveColumnBeforeOtherColumn "pmt_class", "site_addrs"
        '
        ' move a column after another column
        '    to move "site_addrs" after the "pmt_class" column, type
        '    MoveColumnAfterOtherColumn "site_addrs", "pmt_class"
        '
        ' then you have to run the macro on the spreadsheet and then save.
        '
        '==================================================================
        
        '........type here......

        


        
        '==================================================================
        '==================================================================
        
    End If
End Sub



Private Function ConfirmFormat() As Boolean
    Dim result As Boolean
    
    result = True

   ' you can use this function to make sure the spreadsheet
   ' you're working with didn't already have its columns
   ' reordered, or at least make sure it's the correct type of
   ' spreadsheet that your macro is made for.

   ' If Cells(1, 1) <> "expected name of column A" Then
   '     result = False
   ' End If
   ' 
   ' If Cells(1, 2) <> "price" Then
   '     result = False
   ' End If
   ' 
   ' If Cells(1, 3) <> "item name" Then
   '    result = False
   ' End If
   '
   ' If Cells(1, 4) <> "date" Then
   '     result = False
   ' End If
    
    If result = False Then
        MsgBox "this spreadsheet is not in the expected format.  you may have already re-ordered the columns in the spreadsheet."
    End If
    
    ConfirmFormat = result

End Function





'***************************************************************************************

'you do not need to change any code below to use this macro.


'***************************************************************************************



Function AddOne(ByRef lngN As Integer) As Integer
    lngN = lngN + 1
    AddOne = lngN

    ' this function let's you specify the order of columns you want sequentially,
    ' starting at column A, like so:
    '

    ' Dim nextNumber As Integer
    ' nextNumber = 1
    '
    ' MoveColumn "const_type", ColumnLetter(AddOne(nextNumber)) 'col A
    ' MoveColumn "site_cnty", ColumnLetter(AddOne(nextNumber)) 'col B
    ' MoveColumn "site_city", ColumnLetter(AddOne(nextNumber)) 'col C
    ' MoveColumn "site_stnam", ColumnLetter(AddOne(nextNumber)) 'col D

End Function

Private Sub DeleteColumn(ColumnName As String)
    DeleteColumn2 FindColumn(ColumnName)
End Sub

Private Sub MoveColumn(NameOfColumnToMove As String, MoveBeforeCols As String)
    MoveColumnBeforeOtherColumn2 FindColumn(NameOfColumnToMove), MoveBeforeCols
End Sub

Private Sub MoveColumnBeforeOtherColumn(NameOfColumnToMove As String, NameOfColumnToPutBefore As String)
    MoveColumnBeforeOtherColumn2 FindColumn(NameOfColumnToMove), FindColumn(NameOfColumnToPutBefore)
End Sub
Private Sub MoveColumnAfterOtherColumn(NameOfColumnToMove As String, NameOfColumnToPutAfter As String)
    MoveColumnBeforeOtherColumn2 FindColumn(NameOfColumnToMove), FindNextColumn(NameOfColumnToPutAfter)
End Sub

Private Sub DeleteColumn2(Cols As String) 'eg Cols = "A"
    Columns(Cols & ":" & Cols).Delete Shift:=xlToLeft
End Sub

Private Sub MoveColumnBeforeOtherColumn2(ColsToMove As String, MoveBeforeCols As String)
    If ColsToMove <> MoveBeforeCols Then
        Columns(ColsToMove & ":" & ColsToMove).Cut
        Columns(MoveBeforeCols & ":" & MoveBeforeCols).Insert Shift:=xlToRight
    End If
End Sub

Private Function FindColumnX(Name As String, Offset As Integer) As String
    Dim Col As String
    
    For i = 1 To 255
        If Cells(1, i) = Name Then
            Col = ColumnLetter(i + Offset)
            Exit For
        End If
    Next
    
    If Col = "" Then
        
        MsgBox "Can't find column '" & Name & "'.  Make sure you the spreadsheet is in the correct format."
    
        End 'stop processing spreadsheet
        
    End If
    
    FindColumnX = Col
    
End Function
Private Function FindColumn(Name As String) As String
    FindColumn = FindColumnX(Name, 0) 'offset = 0 means just find the column like normal
End Function
Private Function FindNextColumn(Name As String) As String
    FindNextColumn = FindColumnX(Name, 1) 'offset = 1 means get the column AFTER this column
End Function


'i got this ColumnLetter function from freevbcode.
'before you re-publish, check their licensing permissions page.
Function ColumnLetter(ByVal ColumnNumber As Integer) As String
        '
        'example usage:
        '
        'Dim temp As Integer
        'temp = Sheets(1).Range("B2").End(xlToRight).Column
        'MsgBox "The last column of this region is " & _
        '        ColumnLetter(temp)
        '
            
    If ColumnNumber <= 0 Then
        'negative column number
        ColumnLetter = ""
        
    ElseIf ColumnNumber > 16384 Then
        'column not supported (too big) in Excel 2007
        ColumnLetter = ""
        
    ElseIf ColumnNumber > 702 Then
        ' triple letter columns
        ColumnLetter = _
        Chr((Int((ColumnNumber - 1 - 26 - 676) / 676)) Mod 676 + 65) & _
        Chr((Int((ColumnNumber - 1 - 26) / 26) Mod 26) + 65) & _
        Chr(((ColumnNumber - 1) Mod 26) + 65)
    
    ElseIf ColumnNumber > 26 Then
        ' double letter columns
        ColumnLetter = Chr(Int((ColumnNumber - 1) / 26) + 64) & _
                Chr(((ColumnNumber - 1) Mod 26) + 65)
    Else
        ' single letter columns
        ColumnLetter = Chr(ColumnNumber + 64)
    
    End If
End Function

2012-08-03

css border shorthand, does order matter?

does the order of the style, width and color specified in a css border matter?
ie, is style="border: 1px solid black"
the same as style="border: black 1px solid"?

i had trouble finding the answer online, hence this post.

but from what i found, plus some experimentation, the answer is:

no, the order does not matter.

2012-07-23

PrimoPDF a security vulnerability, running as SYSTEM

on a pc with primopdf installed, all users have admin access and can easily make themselves administrators.

i use nitro pdf software's PrimoPDF to convert files into pdf documents.  but once upon a time, when PrimoPDF asked me where to save the pdf document, i saved the file to the desktop.  then i checked the desktop and the pdf was nowhere to be found.  so i tried printing again, and the save as dialog box showed that the file actually was already on the desktop.  weird!  refreshed the desktop, still not there.

so i right clicked the file from within the save as dialog, and went to properties to confirm that the file was on my desktop.


i am on a restricted user account.  how did i save a file to a file in system32?  it looks like the desktop button is mapping to the system's desktop.  weird!  the full path to the file was C:\WINDOWS\system32\config\systemprofile\Desktop.

i suspected PrimoPDF might be running as the SYSTEM.  and it was...


what's the big deal, you might ask?

on a pc with primopdf installed, all users have admin access and can easily make themselves administrators.  D=

let me show you how you can make yourself an administrator on a limited user account on a computer with primopdf installed.

1.  print something.  anything.  choose "PrimoPDF" as the printer.
2.  click "Create PDF" when PrimoPDF appears.
3.  when prompted to save the pdf, type this in the file name field:  c:\windows\system32\*.exe
4.  hit "enter", and find "cmd" in the list.
5.  right click on "cmd", and click "open".
6.  you now have a command prompt running as the system!



7. now, promote yourself to have access to everyone else's files!  just type this:
net localgroup administrators /add "%username%"


my friends can log on to my computer using the guest account, make themselves an admin account and delete all my stuff.  my dad's accountant can remote desktop onto my dad's computer, promote themselves and steal all our company's secrets.  thanks nitro!


luckily, there are many more free pdf creators.  see all these great alternatives to nitro's software:
http://alternativeto.net/software/primopdf/

2012-06-27

solution to Type 'System.Web.UI.WebControls.*' does not have a public property named 'ViewStateMode'.

according to this page, if you get the error,
Type 'System.Web.UI.WebControls.*' does not have a public property named 'ViewStateMode'.
all you have to do is
make sure the target framework is .net framework 4
1. change your web.config
<system.web>
    <compilation debug="true" targetFramework="4.0">
2. change the build options in the property pages for the website in visual studio.


2012-05-21

rename a file in package explorer (eclipse)

it's quite silly how difficult it is to find certain menu items it eclipse.  i wanted to rename a file for which i forgot the ".c" extension, but couldn't find out how to do it!  normally i'd try to convince eclipse to open the project folder using whatever interface (e.g. gnome), but i forget if that's possible and i can't even try because i now i'm getting a "Problem Occurred" / "PermGen space" error which pops up again immediately after i hit ok.  so to save you the lifetime's worth of trouble you may face if you try to rename a file in eclipse using your intuition, i've found a trick for you.

> select the file, hit f2.

2012-04-28

using a makefile in an eclipse java project

if you have java code and rely on a makefile to compile, you can configure eclipse to build your project using your makefile as follows:
  1. create the java project in eclipse
    1. open eclipse.
    2. click file, new, project...
    3. choose java project.
    4. type a project name
    5. un-check use default location and click browse to find the root of your java project which contains your makefile
    6. click finish
  2. add make as a builder
    1. click on the project in the package explorer.
    2. click project, and then click properties.
    3. click builders, and then click new.
    4. choose program and click ok.
    5. in the location textbox, type "/usr/bin/make" (w/o quotes).
      1. warning:  if this is not the location of the "make" program on your computer, determine the location by typing "whereis make" in a terminal window.
    6. in the working directory section choose browse workspace.
    7. choose your project, and click ok.
    8. under arguments, type "all", or the appropriate label in your makefile, plus any other arguments you wish to pass to make.
i'd love to hear if this helped you.

2012-04-15

visual studio 2010 "copy web site" tool is slow; solution: web site publisher

scenario #1)  you don't mind publishing your source code, and you need to publish you aps.net web site via ftp to your host.   visual studio's built in "copy web site" tool is prohibitively slow because it scans the server for changes, and your website has many folders and files. (your host may even throttle your ftp connections after visual studio scans a few directories.)  analyzing the ftp server is unnecessary because you are the only person who updates your website.  you only want to do a one-way sync to the ftp server without scanning the server.  your hosting company does not support svn.

scenario #2) you use, microsoft expression web, and want to publish only changes to the server.  the problem is that their "publish changed files" option does not propagate deletions.  to propagate deletions in expression web, you must use the "publish all files" function, which is much too slow when the remote copy is accessible over only ftp.

solution: web site publisher, the simplest and most genius program ever.  it took me many hours to find it, which is why i felt the need to share it.  you can configure it to scan only your hard drive for new/changed files and deletions, and then publish the changes since you last published to the ftp server.  my solution won't work for *pre-compiled* asp.net web applications.

download it here:  http://www.cryer.co.uk/downloads/websitepublisher/

you must enable the turbo optimization so that it does not scan the server.  click "config", "optimisations", and then check "turbo".


2012-04-04

kindle "show display options" menu is disabled

i am trying out kindle for pc and am reading a textbook.  i found reading to be rather difficult on kindle for pc because of it's jagged scrolling (please complain here).  while looking to add a smooth scrolling option i noticed the view / show display options menu was disabled.

problem: not all books support changing settings like font size and background color.  for example, my textbook has pictures and stuff written in the margins of pages.  if i changed the "words per line" setting, the words would overlap on the pictures or problems would arise from trying to apply features that aren't defined for a textbook.

there is no easy solution.  author's of textbooks need to make books in a e-reading friendly format, which they will have little incentive to do until physical books phase out and e-books really start to catch on.

if you want to know what the dialog box looks like, this is what you're missing out on:

2012-03-06

latex error "image failed (no JPEG header found)"

i use texmaker to write latex documents on windows.  i wanted to insert a graphic using the directions on this page.  i got these errors:

!pdfTeX error: pdflatex (file C:/.../dog.jpg): reading JPEGimage failed (no JPEG header found)==> Fatal error occurred, no output PDF file produced!
i created the jpg file in microsoft paint.  perhaps if i used a different jpeg, it would've worked.

the solution is to open the jpg file in paint, save it as a .png file and then use the png file.

no need to change the latex code if it doesn't include a file extension.  e.g.

\includegraphics{dog}
otherwise, just change the filename.  change
\includegraphics{dog.jpg}
to
\includegraphics{dog.png}

2012-03-05

securely send passwords over email

i've been sending passwords to people over email for years and just realized how bad it would be if someone hacked into my own email account and searched for "password".  this is why we should never send non-temporary passwords over email.  i used to type "delete this email" in the subject line, but this is a better solution.

http://timebomb.it/

timebomb.it lets you send login credentials to people via a link that expires after an hour, day or month.  that way, if a hacker gets into your friend's or co-worker's email and searches for "password", they will only find expired links and no passwords.

just go to timebomb.it and type in the username and password you want to send.


then you'll see the page with the url.  copy the url...

and email it securely!


then, if someone searches for "password" in the recipient's gmail a year later, they get this!



i was going to use kl1p.com, an online clipboard, to send passwords, but they got rid of the option to make the clipboard contents expire after a certain amount of time.  timebomb.it is a good alternative for sending sensitive information that you want to be available for a limited amount of time.