Skip to content

Instantly share code, notes, and snippets.

View joe-oli's full-sized avatar
💭
what the flock? no status to report, i am not a facebook junkie.

joe-oli

💭
what the flock? no status to report, i am not a facebook junkie.
View GitHub Profile
@joe-oli
joe-oli / basicServer101.js
Created November 17, 2018 08:24
basic node.js server (no express) showing GET and POST
/* ============= basicServer101.js ============== */
/* shows
- handling Body in a POST (or PUT) request;
- two http-request handlers can be hooked up to the same event; both get called one after the other... (just experimenting... we could use one handler with if-then inside it)
USAGE:
at a cmd prompt enter:
>node basicServer101
then at a Browser enter:
@joe-oli
joe-oli / uniqueSets.js
Last active December 15, 2018 13:18
unique elements in a Set (by definition) or making Array elements unique
//immutable:
const { List } = require('immutable');
const someList = List([1,2,3,4,4,4,4]);
const uniqueList = someList.toSet();
//ES6:
const someArr = [1,2,3,4,4,4,4];
const uniqueSet = new Set(someArr); //==> {1,2,3,4} uniqueSet.constructor is a Set; typeof uniqueSet = "object"
const uniqueArr = [...uniqueSet]; //==> [1,2,3,4] uniqueList.constructor is an Array; typeof uniqueList = "object"
const uniqueArr2 = Array.from(uniqueSet); //ALT to above line
@joe-oli
joe-oli / loops-breakout.js
Created January 2, 2019 00:22
test breaking out of loops
/*
break out of loops
---------------------
test in node with:
>node loops-breakout
*/
//+++++ use for -loop; +++++++++++++++
console.log('starting for -loop...');
let selectedRows = {};
//add props(or keys) to object.
@joe-oli
joe-oli / whereClauseIN.cs
Created January 3, 2019 08:30
executing SELECT field1,field2 from Tablename WHERE pk IN (1,3,5,69) using EntityFramework
using System.Collections.Generic; //List<>
using System.Data.Entity.Infrastructure; //DbRawSqlQuery
using System.Data.SqlClient; //SqlParameter
using MyNamespace.EFLayer.MyModel; //EFEntities
/* executing SELECT field1,field2 from Tablename WHERE pk IN (1,3,5,69) using EntityFramework;
----------
place the WHERE clause set in an array, e.g. wherePkeysArray = [1,3,5,69]
create a concrete class DTO.ResultObj such that its prop names match exactly the fields in your sql, i.e. field1, field2
*/
@joe-oli
joe-oli / entityFramework-101.cs
Last active January 17, 2019 12:14
Entity Framework attached + detached entities
int pkSeqNo = 123;
//detached entity
MyChildEntity child_entity = new MyChildEntity();
MyParentEntity attachedParentEntity = dbCtx.MyParentEntity
.Where( h => h.seqNo == pkSeqNo)
.Include( h => h.MyChildEntity)
.SingleOrDefault();
@joe-oli
joe-oli / sql-server-101.sql
Created January 21, 2019 08:52
sql server random notes
-- Find tables without primary keys (PKs) in SQL Server database
select schema_name(tab.schema_id) as [schema_name],
tab.[name] as table_name
from sys.tables tab
left outer join sys.indexes pk
on tab.object_id = pk.object_id
and pk.is_primary_key = 1
where pk.object_id is null
order by schema_name(tab.schema_id),
tab.[name]
@joe-oli
joe-oli / sql-server-EF-webapi-example.cs
Last active February 25, 2019 08:51
return sql servername, databasename
/*
--#1 query to retrieve SERVER/DB
select (
select
@@SERVERNAME as ServerName,
db_name() as DatabaseName
-- for XML PATH, root --//<== wraps each record with default <row> element, and supply a default root overall.
-- for XML PATH('item'), root('treetop') --//<== when you want to rename 'row' to 'item', 'root' to 'treetop'
for XML PATH --//<== default <row> element, no root.
-- yields a dodgy column name, say, XML_F52E2B61-18A1-11d1-B105-00805F49916B
@joe-oli
joe-oli / Upsert_OneManyExample.cs
Created March 26, 2019 05:00
UPSERT 1-M DATA EXAMPLE - insert or update within a transaction
//UPSERT 1-M DATA EXAMPLE - insert or update within a transaction
//---------------------------------------------------------------
//
private void Upsert_OneManyExample(OneManyDto myDtoObject)
{
/* ASSUME DTO Object has the form:
myDtoObject = {
oneHeader = ... some object here
} manyLines = ... some array of objects here...
*/
@joe-oli
joe-oli / disable-dir-browse-web.config
Last active August 19, 2019 06:56
disable directory browsing a folder on IIS
//set the Web.config for the site which you want to disable dir-browsing; any child folders within the site are also non-browsable.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<directoryBrowse enable="false"/>
</system.webServer>
</configuration>
//to scope it to a specific folder within the Site or App, use location tag.
@joe-oli
joe-oli / search-recent-browsed-history.txt
Created August 23, 2019 01:51
search recent questions viewed on stackoverflow (or any site really !)
Ctrl/H
Search History (optionally, filter your last browser activity)
No need to Enter, filters on the fly
Works on Chrome and Firefox on Windows; Safari and IE no idea / who cares, but there may be something equivalent.