Tuesday, July 16, 2013

Break captcha in Chinese

Most captchas are in English/numbers.

Here is an interesting video on how to break captchas in Chinese. The key is this writing recognition site http://www.nciku.com/. This is a nice site to help learning Chinese.

Here the Chinese character is not skewed, so it's easy to draw it. It'll be harder if the characters are skewed.

But ultimately, to make it safer, captcha better incorporate some semantic meaning, like asking for an answer to a question with culture background, instead of just typing the character.

Essential PHP security

Essential PHP security. By Chris Shflett. 2006.

Nice book. Basic rules can apply to sites built in other languages.


ADO.NET 4 Database Programming 2010

Murach's ADO.NET 4 Database Programming with VB 2010, 4th Edition. By Anne Boehm, Ged Mead.

- ADO.NET connection types: sql, ole, odbc
- ADO.NET objects: Connection --> command --> 1) data reader, 2) data adaptor --> dataset, binding.
- Stored procedures and parameters
- Transaction. Begin, Commit, Rollback, Savepoint
- GridView/DetailsView: add/edit/delete, select/multi-select, paging. Can implement these myself.
- XML
- LINQ: to: xml/sql/entity/dataset/objects
- Entity Framework

Tuesday, July 9, 2013

Visual C# 2008/2012. By John Sharp

p.151. Nullable type.
   int i = null; // wrong
   int? i = null; // right

p.152. ref, out (must assign value in method).
   Need to declare variable as ref/out at both calling site and function definition.

p.176. Class & Struct
                                                                          struct                    class
type                                                                    value                    reference
live on                                                                 stack                   heap
can declare default ctor?                                      no                       yes
after declare ctor, default ctor auto-created?        yes                      no
automatic initialize fields?                                     no                       yes
can initialize instance fields at declaration?            no                       yes

- Collection:
   - Hashtable
   - SortedList - sorted hash table (RB tree?)

p.207. Parameter Arrays. - variable param list.
    - void func(params int[] a) {...}

p.217. CH 12. Inheritance
   - new, virtual, override, hiding/overriding, protected.
   - extension methods?
   - public, protected, private, internal, protected internal 
   - internal: Internal types or members are accessible only within files in the same assembly,
   - protected v.s. protected internal:
      - protected; derived types may access the member.
      - protected internal; only derived types or types within the same assembly can access that member,
        so they need to be in the same Dynamic Link Library or an executable file.

p.239. Interface, Abstract class, Sealed class.
   - interface => virtual => override => sealed

p.274. Property, get/set

p.295. CH 16. Indexer?

p.311. delegate, event

p.333. CH 18. Generics.
    Queue myQ = new Queue();

p.371. LINQ. Language Integrated Query
   - LINQ, DLINQ, XLINQ.
     - Linq is a programming model that introduces queries as a first-class concept into any Microsoft .NET language
     - DLinq (Linq to SQL) is an extension to Linq that allows querying a database and do object-relational mapping.
     - XLinq (Linq to XML) is an extension to Linq that allows querying/creating/transforming XML documents.
   - After ASP.NET 4.0, emphasis is on Entity Framework, which replaces LINQ.

   - Linq v.s. Entity Framework. (some explanation)
     - LINQ to SQL only supports 1 to 1 mapping of database tables, views, sprocs and functions available in Microsoft SQL Server. It's a great API to use for quick data access construction to relatively well designed SQL Server databases. LINQ2SQL was first released with C# 3.0 and .Net Framework 3.5.
    - LINQ to Entities (ADO.Net Entity Framework) is an ORM (Object Relational Mapper) API which allows for a broad definition of object domain models and their relationships to many different ADO.Net data providers. As such, you can mix and match a number of different database vendors, application servers or protocols to design an aggregated mash-up of objects which are constructed from a variety of tables, sources, services, etc. ADO.Net Framework was released with the .Net Framework 3.5 SP1.

p.420. XAML. Extensible Application Markup Language.
    - WPF - XAML - define interface by XML(XAML), independent from application logic.

p.523. DLINQ. Based on ADO.NET. Data LINQ.

p.557. PART VI. Build web app.
   - ASP.NET server control
   - HTML control (runat="server")
   - theme
   - web forms validation controls.

p.623. Web service
   - REST: request by specifically formatted URL
   - SOAP: request by XML message.

Sams Teach Yourself SQL in 24 hours

CH 4. p.61.
   Normalization - reduce redundancy (will reduce performance due to more JOINs, will use more CPU/mem/IO).
   Denormalization. Combines tables, controlled redundancy. Increased performance.

CH 6. Transaction.
   Commit, Rollback, Savepoint

CH 8. All, Some, Any

CH 9. Aggregate functions.

CH 10. Sorting and Grouping.
   Group by.
   - rollup - get subtotal
   - cube - crosstab reports
   - having - GROUP BY/HAVING is similar to SELECT/WHERE
   - p. 243. UNION (no duplicate rows), UNION ALL (including duplicate rows).
   - INTERSECT
   - EXCEPT

CH 16. p. 256. Indexes.
   - When to avoid using indexes.. p. 261

CH 17. Improve DB performance
   - DB tuning / SQL tuning
   - To avoid full table scan, then use Index

CH 18. Manage DB Users
   - Schema - a collection of DB objects that a user owns.
   - DB user - aschema owner
   - Default schema - dbo (db owner)

CH 19. p. 299. Manage DB security.
   - Privilege
   - Control user access. GRANT, REVOKE, ROLE

CH 20. View, Synonym

CH 21. System Catalog

CH 22. Advanced SQL

MSSQL Server 2008

p.103. CH 7. Partitioning

p.219. CH 15. DB snapshots. CREATE database AS Snapshot

p.375. Part VII. Business Intelligence.
CH24. SSIS - SQL Server Integration Services
CH25. SSRS - SQL Server Reporting Services
CH26. SSAS - SQL Server Analysis Services

SSMS - SQL Server Management Studio

Big Data for Dummies

- Part I. Big Data. 3 characteristics: volume, velocity, variety
   - technology: MapReduce, BigTable, Hadoop (started at Yahoo)
- Part II. Tech foundations. p. 68. Hypervisor
   - cloud: Amazon (EC2, 2006), Google (Big Data), MS (Azure), Rackspace, NASA (OpenStack).
- Part III. Management
   - CH 7. Relational Database. CRUD, ACID.
                Non-relational Database.
   - CH 8. MapReduce
   - CH 9. Hadoop
- Part IV. Analytics & Big Data
   - p.145. Data Mining: classfication, log regression, NN, clustering (k-means etc).

Some C#, ASP.NET and SQL books

Browsed some C#, ASP.NET and SQL books. Quickly get through large amount of material, to review and refresh old knowledge, and gain an understanding of new advancement. Most of these books are written for beginners. However, each more or less covers things I did not notice in the past.

- ASP.NET 2.0 in C# 2005
- Learn Microsoft Visual C# 2010. By John Paul Mueller
- murach's ASP.NET web programming with C# 2010, 4th Edition.
- Visual C# 2008. By John Sharp
- Visual C# 2012. By John Sharp. (This book is a minor update from the 2008 version)
- Sams Teach Yourself SQL in 24 hours
- MS SQL Server 2008, by Mike Hotek.
- Big Data for Dummies

Long words short, ASP.NET evolution (see wiki page on ASP.NET):

- 2002.1   1.0  OO, based on windows programming, can use DLL. ADO.NET. VS.NET
- 2003.4   1.1  Automatic input validation; mobile controls. Bug fix, performance increase. VS.NET 2003.
- 2005.11  2.0 Major updates: Partial class, Generics, Anonymous methods, Iterators, master page, theme, navigation, Grid/Form/DetailsView, Login, skin etc. VS.NET 2005
- 2006.11  3.0 WCF, WPF, WFF,
- 2007.11  3.5 MVC (easier to test and for plugable IoC containers etc.), Silverlight, LINQ, Ajax, ADO.NET Entity Framework, ListView, DataPager etc. VS.NET 2008. Windows Server 2008.
- 2012.4    4.0 Parallel extensions.
- 2012.8    4.5 VS.NET 2012. Windows Server 2012. Window 8.

Wednesday, July 3, 2013

sed

Use sed to replace some string in a large file (example tested is 2GB in size):

sed -i 's/old_value/new_value/g' filename

Some more examples are there. It seems like in vi using "%s/old_value/new_value/g" is much slower.

Blog Archive

Followers