Skip to content

Instantly share code, notes, and snippets.

Finding keys and values
Objects, in Vanilla JavaScript, use the same syntax as arrays
for accessing property
values.That is, the square bracket notation but typically with a human - readable
string, instead of a numerical index.However, the same issues that exist with
numerical indices and arrays exist with objects and keys too.Just because the key
is a string doesn 't mean that we know which keys are available. Sometimes, we
have to search the object to find the key we 're looking for.
We use the findKey()
function to locate the key of the first object property that
@hungtran-it
hungtran-it / css_resources.md
Created March 5, 2014 15:06 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides

@hungtran-it
hungtran-it / javascript_resources.md
Created March 5, 2014 15:06 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@hungtran-it
hungtran-it / new_gist_file
Created July 5, 2013 17:17
Center DIV with Dynamic Height
CSS
* { margin: 0; padding: 0; }
#page{display:table;overflow:hidden;margin:0px auto;}
*:first-child+html #page {position:relative;}/*ie7*/
* html #page{position:relative;}/*ie6*/
#content_container{display:table-cell;vertical-align: middle;}
*:first-child+html #content_container{position:absolute;top:50%;}/*ie7*/
* html #content_container{position:absolute;top:50%;}/*ie6*/
@hungtran-it
hungtran-it / new_gist_file
Created July 5, 2013 17:16
Browser Specific Hacks
/* IE 6 */
* html .foo { }
/* IE 7 */
*+html .yourclass{ }
/* IE 7 and modern browsers */
html>body .yourclass { }
/* Modern browsers (not IE 7) */
@hungtran-it
hungtran-it / new_gist_file
Created July 1, 2013 13:48
/jpg|jpeg|png|gif$/
function setIconTo(helpIcon) {
isImage = /jpg|jpeg|png|gif$/
if (helpIcon == undefined)
{ icon = "[?]"; }
else if (isImage.test(helpIcon))
{ icon = "<img src='"+helpIcon+"'>"; }
else
{ icon = helpIcon; }
}
@hungtran-it
hungtran-it / new_gist_file
Created June 22, 2013 12:19
Reuse Parameterized Queries with LINQ to SQL
Problem
You need to execute the same parameterized query multiple times with different
parameter values, but you want to avoid the overhead of parsing the query expression
tree to build the parameterized SQL each time the query executes.
Solution
Use the CompiledQuery.Compile method to build an expression tree that will not have
to be parsed each time the query is executed with new parameters:
var GetEmployees =
CompiledQuery.Compile((Northwind db, string ac, string ttl) =>
from employee in db.Employees
From Framework 4.0, the Lazy<T> class is available to help with lazy initialization.
If instantiated with an argument of true, it implements the thread-safe initialization
pattern just described.
Lazy<T> actually implements a micro-optimized version of this
pattern, called double-checked locking. Double-checked locking
performs an additional volatile read to avoid the cost of obtaining
a lock if the object is already initialized.
To use Lazy<T>, instantiate the class with a value factory delegate that tells it how to
initialize a new value, and the argument true. Then access its value via the Value
property:
To configure ASP.NET to use deferred request validation, update the httpRuntime >
requestValidationMode attribute in web.config to 4.5:
<httpRuntime requestValidationMode="4.5" />
When deferred request validation is enabled, the validation process will get triggered
the first time the application calls the request collection (e.g., Request.Form["post_con
tent"]). To skip the input validation, use the HttpRequest.Unvalidated() helper
method to access an unvalidated collection:
using System.Web.Helpers;
var data = HttpContext.Request.Unvalidated().Form["post_content"];
Microsoft has included a portion of the popular Microsoft Anti-XSS Library in
@hungtran-it
hungtran-it / new_gist_file
Created June 22, 2013 07:30
Adding JSONP support to ASP.NET MVC controller actions
public class JsonpResult : JsonResult
{
public string Callback { get; set; }
public JsonpResult()
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet;
}
public override void ExecuteResult(ControllerContext context)
{
var httpContext = context.HttpContext;