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 / install-http-server-notes.txt
Created October 5, 2019 16:56
install local http server
//step 1. check is server installed globally?
>npm list http-server -g
C:\Users\joe.oli\AppData\Roaming\npm
`-- (empty)
//step 2. install server
>npm install http-server -g
C:\Users\joe.oli\AppData\Roaming\npm\http-server -> C:\Users\joe.oli\AppData\Roaming\npm\node_modules\http-server\bin\http-server
C:\Users\joe.oli\AppData\Roaming\npm\hs -> C:\Users\joe.oli\AppData\Roaming\npm\node_modules\http-server\bin\http-server
+ [email protected]
@joe-oli
joe-oli / promises-terminology.txt
Created October 8, 2019 14:57
promises terminology
States and Fates
================
This document helps clarify the different adjectives surrounding promises, by dividing them up into two categories: states and fates.
Overview and Operational Definitions
States
-------
Promises have three possible mutually exclusive states: fulfilled, rejected, and pending.
A promise is fulfilled if promise.then(f) will call f "as soon as possible."
@joe-oli
joe-oli / animal.js
Created October 9, 2019 01:05
OOP javascript
function newAnimal(spec = {}){
let { name = 'it', word = 'nothing' } = spec,
talk = () => console.log( name + ' says ' + word);
return Object.freeze({ name, word, talk });
}
function newAnimalMovement(spec = {}) {
let { name = 'it' } = spec,
fly = () => console.log(name + ' is flying: flap flap'),
swim = () => console.log(name + ' is swimming: splish splash'),
@joe-oli
joe-oli / photos-data.json
Created October 9, 2019 01:42
instagram sample data as json
// this is a giant JSON object you have received back from the Instagram API
// Use it for good, solely on the front end, to create a photo gallery widget!
const instagramResponse = {
"meta": {
"code": 200
},
"data": [
{
"attribution": null,
@joe-oli
joe-oli / dummy-logs.json
Created October 9, 2019 01:46
dummy json data
[
{
"level": "error",
"message": "All your base are belong to us"
},
{
"level": "warning",
"message": "Good news everyone!"
},
{
@joe-oli
joe-oli / jquery-in-chrome.txt
Created October 9, 2019 02:21
using jquery in console
Want to use jQuery from the Browser console?
1. load a page that loads jquery as usual in a script tag.
2. Otherwise, include jQuery in any page by executing this code in the console:
var scr = document.createElement("script");
scr.src = "http://code.jquery.com/jquery-3.4.1.min.js";
document.body.appendChild(scr);
//After abpve script, you can use jQuery from the console;
@joe-oli
joe-oli / Html2Markdown.cs
Created October 11, 2019 00:39
html to markdown
/* install pandoc first;
https://pandoc.org/installing.html
https://github.com/jgm/pandoc/releases/tag/2.7.3
*/
public string Convert(string source)
{
string processName = @"C:\Program Files\Pandoc\bin\pandoc.exe";
string args = String.Format(@"-r html -t mediawiki");
ProcessStartInfo psi = new ProcessStartInfo(processName, args);
@joe-oli
joe-oli / sqlLocalDB.md
Last active October 17, 2019 03:11
phantom db lying around, after mdf, ldf files were deleted

My answer on stackoverflow.com, so I remember how to do this next time.

ASP.NET MVC 4: Basically I've followed a tutorial and decided to delete the .mdf file afterwards.

Now whenever I try to run the application I get the following error: "Cannot attach the file *.mdf as database"

To fix this using SQL SERVER Management Studio

@joe-oli
joe-oli / FileSnippets.cs
Last active October 26, 2019 02:42
Files, streams, etc
//1.) for small files only, load all contents into memory
string content = File.ReadAllText("path/to/TextFile.txt", Encoding.UTF8);
//2.) ...or read lines into an array
string[] linesArr = File.ReadAllLines("path/to/TextFile.txt", Encoding.UTF8);
foreach (string line in linesArr) {
//do stuff with each line.
}
//3.) ... or open a stream for reading (StreamReader)
@joe-oli
joe-oli / DemoCrawler.cs
Created October 25, 2019 13:08
example crawler using HtmlAgilityPack
public static class OtoDomCrawler
{
public static async Task<List<Page>> Search(string url)
{
var offers = new List<Page>();
while (url != null)
{
var html = (await new HtmlWeb().LoadFromWebAsync(url)).DocumentNode;
offers.AddRange(GetOffers(html));
url = html.SelectSingleNode("//a[@data-dir='next']")?.GetAttributeValue("href", null);