Skip to content

Instantly share code, notes, and snippets.

View ChrisMoney's full-sized avatar

Chris Weathers ChrisMoney

  • Onevested
  • St. Louis, MO
View GitHub Profile
@ChrisMoney
ChrisMoney / returnMultipleTypes.cs
Created June 17, 2024 13:36
Return two types C#
(string, string, string) LookupName(long id) // tuple return type
{
... // retrieve first, middle and last from data storage
return (first, middle, last); // tuple literal
}
@ChrisMoney
ChrisMoney / requestObject.js
Last active June 10, 2024 15:43
JS - Javascript HTTP Request Object
var xhr = new XMLHttpRequest;
xhr.open("GET", url);
xhr.send();
// ********************************
// Return Json object from server
// ********************************
var id = 1;
var req = new XMLHttpRequest();
@ChrisMoney
ChrisMoney / knockout.js
Created June 9, 2024 17:53
Knockout Javascript example
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>
// data model
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.pureComputed(function() {
@ChrisMoney
ChrisMoney / promise.js
Created June 9, 2024 14:17
Promise - Javascript
/*
A promise in JavaScript is an object that represents the eventual completion or failure of an asynchronous operation.
*/
new Promise((resolveOuter) => {
resolveOuter(
new Promise((resolveInner) => {
setTimeout(resolveInner, 1000);
}),
);
@ChrisMoney
ChrisMoney / observable.js
Created June 9, 2024 14:11
Observable - Javascript
/* Observables allow you to track changes or data over time,
rather than just waiting for a single result like with promises.
*/
// Create an Observable that emits a value every second
const observable = Rx.Observable.interval(1000);
// Subscribe to the Observable and print the emitted values to the console
observable.subscribe(value => console.log(value));
@ChrisMoney
ChrisMoney / angularFileStack.txt
Last active June 9, 2024 14:02
Angular File Stack
HTML file (.html)
CSS file (.css)
Typescript file (.ts)
Test file (.spec.ts)
@ChrisMoney
ChrisMoney / fizzBuzzPop.cs
Last active June 8, 2024 16:17
Fizz Buzz Pop
var itmes = new int[] { 1, 2, 3 }
// Loop from 1 to n (inclusive)
for (int i = items; i <= items.Count; ++i) {
// Check if i is divisible by both 3 and 5
if (i % 3 == 0 && i % 5 == 0) {
// Add "FizzBuzz" to the result vector
console.writeline("FizzBuzz");
@ChrisMoney
ChrisMoney / sqlFactory.cs
Last active June 8, 2024 19:05
Read SQL connection string from XML
/* This is an example of a connectionString node.
<connectionStrings>
<add name="YourConnectionStringKey"
providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=YourDB;Trusted_Connection=Yes" />
</connectionStrings>
*/
// Global Var outside of CRUD methods
@ChrisMoney
ChrisMoney / azureQuery.cs
Last active June 8, 2024 19:14
Azure Query
// Global vars
private SqlConnection _connection;
SqlConnectionStringBuilder conn = new SqlConnectionStringBuilder();
//Azure SQL Server Name
conn.DataSource = "mssqltipsserver.database.windows.net";
//User to connect to Azure
conn.UserID = "admindaniel";
//Password used in Azure
conn.Password = "mypws@#&*234!";
@ChrisMoney
ChrisMoney / await-async.js
Created May 23, 2024 19:24
JS Await and Async
function resolveAfter2Seconds() {
return new Promise((resolve) => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');