Skip to content

Instantly share code, notes, and snippets.

View codenamejason's full-sized avatar
:octocat:
🫠

<jaxcoder /> codenamejason

:octocat:
🫠
View GitHub Profile
@codenamejason
codenamejason / 01-directory-structure.md
Created June 7, 2016 19:13 — forked from tkissing/01-directory-structure.md
Anatomy of a JavaScript/Node project.

Directory structure for JavaScript/Node Projects

While the following structure is not an absolute requirement or enforced by the tools, it is a recommendation based on what the JavaScript and in particular Node community at large have been following by convention.

Beyond a suggested structure, no tooling recommendations, or sub-module structure is outlined here.

Directories

  • lib/ is intended for code that can run as-is
  • src/ is intended for code that needs to be manipulated before it can be used
// Get selected element
var s = document.getElementById('MySelect');
// Index to add the option
var i = 0;
// New option('text', 'value')
s.options[i++] = new Option('text', 'value');
s.options[i++] = new Option('Vermont', 'VT');
// Set a selected index
s.selectedIndex = 1;
// Or
// Add an image
function createImage() {
// Add to bottom of page(s)
var img = document.CreateElement('img');
img.setAttribute("src", "/images/image.png");
("id", );
("width", "250");
("height", "250");
("style", "");
// Adds to bottom of page(s)
// Fires function(s) on pageload
function() {
setTimeout("timerFinished()", 5000);
}
// Method called after time
function timerFinished() {
alert("5 Seconds Have Passed!");
}
[Service Contract]
public interface ImathService
{
[Operational Contract]
Int32 Sum(Int32 a, Int32 b);
[Operational Contract]
Int32 Difference(Int32 a, Int32 b);
[Operational Contract]
Int32 Product(Int32 a, Int32 b);
[Operational Contract]
// Detect local storage on client computer
function localStorageSupported() {
try {
return "localStorage" in window &&
window["localStorage"] !== null;
}
catch (e)
{
return false;
}
<tr data-bind="css: {rowAlt: $data.isActive() && ($index() % 2 == 1), rowInactive: $data.isActive() == false}">
//This example creates a big list with a nested list for each item on the page, each with all of the property names used in that item.
var outer = document.createElement('ul');
var items = document.getItems();
for (var item = 0; item < items.length; item += 1) {
var itemLi = document.createElement('li');
var inner = document.createElement('ul');
for (var name = 0; name < items[item].properties.names.length; name += 1) {
var propLi = document.createElement('li');
propLi.appendChild(document.createTextNode(items[item].properties.names[name]));
@codenamejason
codenamejason / RandomString.cs
Created July 19, 2016 14:06
Creates random string in C#
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var random = new Random();
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
<time itemprop="openingHours" datetime="Mo,Fr 08:00-16:00">Monday Through Friday 8-6pm</time>
/*Logo*/
ImageObject =
priceRange = "$$$"
paymentAccepted = "Cash, Credit,Paypal"