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 / npm-various-cmds.txt
Last active November 19, 2020 17:08
npm various commands
//view latest version only
>npm view react-scripts version
//view all versions
>npm view react-scripts versions
//#1 view all versions of a lib on the remote npm server.
>npm view react-bootstrap versions --json
@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 / SQL-Restore.sql
Last active May 14, 2020 04:39
RESTORE Sql-Server BACKUP using scripts
-- #1 determine logical names / physical names
declare @sourceFile varchar(150) = 'D:\Path\To\File\Mybackup.BAK'
RESTORE FILELISTONLY
FROM DISK = @sourceFile
GO -- go clears any variables below here.. need to redefine them again.
-- #2 copy logical filenames from step#1, and define target filenames
/*
@joe-oli
joe-oli / linux101.txt
Last active December 25, 2022 04:56
miscel linux commands
-- #1. The following will search everything from / and children, for the command whoami
$ find / -iname "whoami"
-- #2. Install chntpw on Kali Linux Light 64 Bit (default pwd for root is toor)
$ apt-get install chntpw
$ sudo apt-get install chntpw //if you are not already root.
-- #3. Mount drive
$ sudo mount -t ntfs /dev/blah1/blah2 /mnt/windows