text:
# Configuration
<!-- [[TOC]] -->

## Publishing the Configuration

To publish the TwoStream configuration file in your Application, run the following command

```bash
$ php artisan vendor:publish --provider="CupOfTea\TwoStream\TwoStreamServiceProvider" --tag="config"
```

Once you have done that, you can find the TwoStream configuration inside `config/twostream.php`. This step is optional, and if you know which settings you want to change, you can just create the `config/twostream.php` file yourself and place those settings inside.

## Configuring TwoStream

You only need to overwrite the settings you want to change. You can remove any items where you want to use the default settings from your Application's TwoStream Configuration file. Below is a list of all avialable settings.

### Response Settings

These are the default settings for how TwoStream should handle responses:

 - `response.recipient`: To which clients the Controller Response should be sent to if no client is specified. By default this is set to `'requestee'` so you don't accidentally send sensitive data to all users. You can modify this setting as you like. This setting supports the following options:
   - `'all'`: The response will be sent to all subscribed Clients.
   - `'except'`: The response will be sent to all subscribed Clients except the Client that made the request.
   - `'requestee'`: The response will be sent to the Client that made the request.
 - `response.rpc.enabled`: Enable/Disable RPCs for your Application. This setting is disabled by default.
 - `response.rpc.success`: Default response message for a successful RPC.
 - `response.rpc.error.enabled`: Default error message for when the Procedure is not found.
 - `reponse.rpc.error.disabled`: Default error message for when RPC is disabled.

### WebSocket Settings

These are the settings for the TwoStream WebSocket Server:

 - `websocket.port`: Default port on which the React Socket Server will listen for incoming connections. This option can also be set in the artisan command. More info on how to do that in the [Server Documentation](http://twostream.cupoftea.io/docs/server/). The default port is `1111`.

### Push Settings

These are the settings for pushing messages from Server to Client:

 - `push.enabled`: Enable/Disable push messages from your Server. This setting is disabled by default and **ZeroMQ PHP Extension** to work. More info on this can be found under [Installation / Push Requirements](http://twostream.cupoftea.io/docs/installation/#push-requirements).
 - `push.port`: The default port for ZeroMQ Connections. This is used to we can connect to all Socket connections and broadcast messages from the back-end.

### Legacy Settings

 - `flash.allowed`: Allow legacy browsers to connect with the [websocket polyfill](https://github.com/gimite/web-socket-js).
 - `flash.port`: The web-socket-js fallback requires a Flash Socket Policy file. This setting allows you to change the port on which the Flash Policy is located. Don't forget to tell the Client where the polici is located. For example in JS: `WebSocket.loadFlashPolicyFile("xmlsocket://myhost.com:843");` This will cause a connection delay of about 2-3 seconds.

gha_language: PHP


text:
---
layout: post
title: 'Short Tutorial: Cleaning up downloaded files'
author: jeri.elizabeth

permalink: /blog/2012/11/28/short-tutorial-cleaning-up-downloaded-files-draft-2/
tags: digital, teaching, tutorial

---
So you used wget or Python to pull down a collection of files from the web. Excellent! But in looking through your loot, you notice that a number of the files are oddly small and, on further examination, find that they are functionally empty. How do you clean up your collection of files quickly?

There are a number of very powerful command line tools built into UNIX systems (Mac and Linux) that allow you to manipulate your files quickly and easily. This is a brief tutorial on how to use those tools to locate all of the files that are too small and then remove those files from your collection.

Begin by navigating in Terminal to your collection of folders. For example, my files were located a couple of folders downs within my Documents folder.

	cd Documents/Github/Clio3/Webscraping/hymn-files

Once in the folder with your downloaded files, you need to find a way to isolate out the files that are too small to be interesting. To do this, use the `find` command.

If the files we are interested in sorting through are all one file type (in my case they're .json files), we can tell the computer to find all of the files of a particular type and particular size as follows:

	find *.json -size 28c

This would find all of the json files that are 28 bytes in size.

However, we want all the files that are 28 bytes or less.

	find *.json -size -28c

This is important in my case because the files are not truly empty. There is a simple way to identify truly empty files, if that is more appropriate for your data.

	find *.json -empty

You can also add

	-maxdepth 1

if there are additional folders that you do not want to work through.

Finding the files is great, but now we need to do something with that collection of files.

There are two ways you can do this. First, you can simply add a delete option to your command, as follows:

	find *.json -size -28c -delete

In general, this should work. However, if you are dealing with a large number of files, it is often better to use a pipe (`|`). The pipe takes the results of the first command and feeds them to the second command. In the example below, we are taking the results of the find command and passing them to the remove command (`rm`).

	find *.json -size -28c | xargs rm

You will notice that we included `xargs` on the right side of the pipe. Xargs helps the computer handle a long list of file names.

Note: The Wikipedia entry on xargs suggests using `-0` (zero) when dealing with file names with spaces in them as xargs defaults to separating at white space (another reason to avoid spaces in filenames). If you run this command without `-0` and it doesn't work, try adding the `-0`.

And the command we are running on each filename is `rm` or remove. rm has a number of options that you can research, some of which really make data un-recoverable and should be used with care. However, a basic `rm` command will be sufficient for this example.

Run this command to remove all of the files less than 28 bytes from your current directory.

(I used 28 bytes because the computer was having trouble with 0 and all of the files I wanted to keep were larger than 28 bytes. Not exactly sure why 0 was a problem but this is why experimenting with the find options before moving on to removing the files is a good idea!)

license: MIT

branch_name: refs/heads/main

extension: md

gha_language: HTML

gha_license_id: MIT

license_type: permissive


text:
# WeakPoint (Version 0.2.3)

WeakPoint is a static slideshow generator.

* Use **Markdown** to write your slides
* Display your slides in Web browser
* NOT a powerful slideshow authering tool
* NOT WYSIWYG

## DEMO

[WeakPoint: Weak is more powerful](http://blog.chengyichao.info/weakpoint/#/step-1)

## Install

The recommended way to install WeakPoint is to use pip:

    $ pip install weakpoint

Create a template:

    $ weakpoint init ~/my-file

The default theme is "light" and you can specify it with "-t" option:

    $ weakpoint init ~/my-file -t dark

Generate the slideshow:

    $ weakpoint gen

## Dependencies

* [Jinja2](http://jinja.pocoo.org/)
* [misaka](http://misaka.61924.nl/)
* [Python-Markdown](http://packages.python.org/Markdown/)
* [PyYAML](http://pyyaml.org/)
* [impress.js](http://bartaz.github.com/impress.js)
* [jmpress.js](https://github.com/shama/jmpress.js/)

## Contributors

Michael Tiller

branch_name: refs/heads/master


text:
---
title: "JavaScript Promises: an introduction"
subhead: >
  Promises simplify deferred and asynchronous computations. A promise represents
  an operation that hasn't completed yet.
description: >
  Promises simplify deferred and asynchronous computations. A promise represents
  an operation that hasn't completed yet.
date: 2013-12-16
updated: 2021-01-18
tags:
  - javascript
authors:
  - jakearchibald
feedback:
  - api
---

Developers, prepare yourself for a pivotal moment in the history of
web development.

[Drumroll begins]

Promises have arrived in JavaScript!

[Fireworks explode, glittery paper rains from above, the crowd goes wild]

At this point you fall into one of these categories:

* People are cheering around you, but you're not sure what all the fuss is
  about. Maybe you're not even sure what a "promise" is. You'd shrug, but the
  weight of glittery paper is weighing down on your shoulders. If so, don't
  worry about it, it took me ages to work out why I should care about this
  stuff. You probably want to begin at the [beginning](#whats-all-the-fuss-about).
* You punch the air! About time right? You've used these Promise things before
  but it bothers you that all implementations have a slightly different API.
  What's the API for the official JavaScript version? You probably want to begin
  with the [terminology](#promise-terminology).
* You knew about this already and you scoff at those who are jumping up and
  down like it's news to them. Take a moment to bask in your own superiority,
  then head straight to the [API reference](#promise-api-reference).

## What's all the fuss about? {: #whats-all-the-fuss-about }

JavaScript is single threaded, meaning that two bits of script cannot run at
the same time; they have to run one after another. In browsers, JavaScript
shares a thread with a load of other stuff that differs from browser to
browser. But typically JavaScript is in the same queue as painting, updating
styles, and handling user actions (such as highlighting text and interacting
with form controls). Activity in one of these things delays the others.

As a human being, you're multithreaded. You can type with multiple fingers,
you can drive and hold a conversation at the same time. The only blocking
function we have to deal with is sneezing, where all current activity must
be suspended for the duration of the sneeze. That's pretty annoying,
especially when you're driving and trying to hold a conversation. You don't
want to write code that's sneezy.

You've probably used events and callbacks to get around this. Here are events:

```js
var img1 = document.querySelector('.img-1');

img1.addEventListener('load', function() {
  // woo yey image loaded
});

img1.addEventListener('error', function() {
  // argh everything's broken
});
```

This isn't sneezy at all. We get the image, add a couple of listeners, then
JavaScript can stop executing until one of those listeners is called.

Unfortunately, in the example above, it's possible that the events happened
before we started listening for them, so we need to work around that using
the "complete" property of images:

```js
var img1 = document.querySelector('.img-1');

function loaded() {
  // woo yey image loaded
}

if (img1.complete) {
  loaded();
}
else {
  img1.addEventListener('load', loaded);
}

img1.addEventListener('error', function() {
  // argh everything's broken
});
```

This doesn't catch images that errored before we got a chance to listen for
them; unfortunately the DOM doesn't give us a way to do that. Also, this is
loading one image. Things get even more complex if we want to know when a set
of images have loaded.

## Events aren't always the best way

Events are great for things that can happen multiple times on the same
object—`keyup`, `touchstart` etc. With those events you don't really care
about what happened before you attached the listener. But when it comes to
async success/failure, ideally you want something like this:

```js
img1.callThisIfLoadedOrWhenLoaded(function() {
  // loaded
}).orIfFailedCallThis(function() {
  // failed
});

// and…
whenAllTheseHaveLoaded([img1, img2]).callThis(function() {
  // all loaded
}).orIfSomeFailedCallThis(function() {
  // one or more failed
});
```

This is what promises do, but with better naming. If HTML image elements had a
"ready" method that returned a promise, we could do this:

```js
img1.ready()
.then(function() {
  // loaded
}, function() {
  // failed
});

// and…
Promise.all([img1.ready(), img2.ready()])
.then(function() {
  // all loaded
}, function() {
  // one or more failed
});
```

At their most basic, promises are a bit like event listeners except:

* A promise can only succeed or fail once. It cannot succeed or fail twice,
  neither can it switch from success to failure or vice versa.
* If a promise has succeeded or failed and you later add a success/failure
  callback, the correct callback will be called, even though the event took
  place earlier.

This is extremely useful for async success/failure, because you're less
interested in the exact time something became available, and more interested
in reacting to the outcome.

## Promise terminology {: #promise-terminology }

[Domenic Denicola](https://twitter.com/domenic) proof read the first draft
of this article and graded me "F" for terminology. He put me in detention,
forced me to copy out
[States and Fates](https://github.com/domenic/promises-unwrapping/blob/master/docs/states-and-fates.md)
100 times, and wrote a worried letter to my parents. Despite that, I still
get a lot of the terminology mixed up, but here are the basics:

A promise can be:

* **fulfilled** - The action relating to the promise succeeded
* **rejected** - The action relating to the promise failed
* **pending** - Hasn't fulfilled or rejected yet
* **settled** - Has fulfilled or rejected

[The spec](https://www.ecma-international.org/ecma-262/#sec-promise-objects)
also uses the term **thenable** to describe an object that is promise-like,
in that it has a `then` method. This term reminds me of ex-England Football
Manager [Terry Venables](https://en.wikipedia.org/wiki/Terry_Venables) so
I'll be using it as little as possible.

## Promises arrive in JavaScript!

Promises have been around for a while in the form of libraries, such as:

* [Q](https://github.com/kriskowal/q)
* [when](https://github.com/cujojs/when)
* [WinJS](https://msdn.microsoft.com/en-us/library/windows/apps/br211867.aspx)
* [RSVP.js](https://github.com/tildeio/rsvp.js)

The above and JavaScript promises share a common, standardized behaviour
called [Promises/A+](https://github.com/promises-aplus/promises-spec). If
you're a jQuery user, they have something similar called
[Deferreds](https://api.jquery.com/category/deferred-object/). However,
Deferreds aren't Promise/A+ compliant, which makes them
[subtly different and less useful](https://thewayofcode.wordpress.com/tag/jquery-deferred-broken/),
so beware. jQuery also has
[a Promise type](https://api.jquery.com/Types/#Promise), but this is just a
subset of Deferred and has the same issues.

Although promise implementations follow a standardized behaviour, their
overall APIs differ. JavaScript promises are similar in API to RSVP.js.
Here's how you create a promise:

```js
var promise = new Promise(function(resolve, reject) {
  // do a thing, possibly async, then…

  if (/* everything turned out fine */) {
    resolve("Stuff worked!");
  }
  else {
    reject(Error("It broke"));
  }
});
```

The promise constructor takes one argument, a callback with two parameters,
resolve and reject. Do something within the callback, perhaps async, then call
resolve if everything worked, otherwise call reject.

Like `throw` in plain old JavaScript, it's customary, but not required, to
reject with an Error object. The benefit of Error objects is they capture a
stack trace, making debugging tools more helpful.

Here's how you use that promise:

```js
promise.then(function(result) {
  console.log(result); // "Stuff worked!"
}, function(err) {
  console.log(err); // Error: "It broke"
});
```

`then()` takes two arguments, a callback for a success case, and another
for the failure case. Both are optional, so you can add a callback for the
success or failure case only.

JavaScript promises started out in the DOM as "Futures", renamed to "Promises",
and finally moved into JavaScript. Having them in JavaScript rather than the
DOM is great because they'll be available in non-browser JS contexts such as
Node.js (whether they make use of them in their core APIs is another question).

Although they're a JavaScript feature, the DOM isn't afraid to use them. In
fact, all new DOM APIs with async success/failure methods will use promises.
This is happening already with
[Quota Management](https://dvcs.w3.org/hg/quota/raw-file/tip/Overview.html#idl-def-StorageQuota),
[Font Load Events](http://dev.w3.org/csswg/css-font-loading/#font-face-set-ready),
[ServiceWorker](https://github.com/slightlyoff/ServiceWorker/blob/cf459d473ae09f6994e8539113d277cbd2bce939/service_worker.ts#L17),
[Web MIDI](https://webaudio.github.io/web-midi-api/#widl-Navigator-requestMIDIAccess-Promise-MIDIOptions-options),
[Streams](https://github.com/whatwg/streams#basereadablestream), and more.

## Browser support & polyfill

There are already implementations of promises in browsers today.

As of Chrome 32, Opera 19, Firefox 29, Safari 8 & Microsoft Edge,
promises are enabled by default.

To bring browsers that lack a complete promises implementation up to spec
compliance, or add promises to other browsers and Node.js, check out
[the polyfill](https://github.com/jakearchibald/ES6-Promises#readme)
(2k gzipped).

## Compatibility with other libraries

The JavaScript promises API will treat anything with a `then()` method as
promise-like (or `thenable` in promise-speak _sigh_), so if you use a library
that returns a Q promise, that's fine, it'll play nice with the new
JavaScript promises.

Although, as I mentioned, jQuery's Deferreds are a bit … unhelpful.
Thankfully you can cast them to standard promises, which is worth doing
as soon as possible:

```js
var jsPromise = Promise.resolve($.ajax('/whatever.json'))
```

Here, jQuery's `$.ajax` returns a Deferred. Since it has a `then()` method,
`Promise.resolve()` can turn it into a JavaScript promise. However,
sometimes deferreds pass multiple arguments to their callbacks, for example:

```js
var jqDeferred = $.ajax('/whatever.json');

jqDeferred.then(function(response, statusText, xhrObj) {
  // ...
}, function(xhrObj, textStatus, err) {
  // ...
})
```

Whereas JS promises ignore all but the first:

```js
jsPromise.then(function(response) {
  // ...
}, function(xhrObj) {
  // ...
})
```

Thankfully this is usually what you want, or at least gives you access to
what you want. Also, be aware that jQuery doesn't follow the convention of
passing Error objects into rejections.

## Complex async code made easier

Right, let's code some things. Say we want to:

1. Start a spinner to indicate loading
1. Fetch some JSON for a story, which gives us the title, and urls for each chapter
1. Add title to the page
1. Fetch each chapter
1. Add the story to the page
1. Stop the spinner

… but also tell the user if something went wrong along the way. We'll want
to stop the spinner at that point too, else it'll keep on spinning, get
dizzy, and crash into some other UI.

Of course, you wouldn't use JavaScript to deliver a story,
[serving as HTML is faster](https://jakearchibald.com/2013/progressive-enhancement-is-faster/),
but this pattern is pretty common when dealing with APIs: Multiple data
fetches, then do something when it's all done.

To start with, let's deal with fetching data from the network:

## Promisifying XMLHttpRequest

Old APIs will be updated to use promises, if it's possible in a backwards
compatible way. `XMLHttpRequest` is a prime candidate, but in the mean time
let's write a simple function to make a GET request:

```js
function get(url) {
  // Return a new promise.
  return new Promise(function(resolve, reject) {
    // Do the usual XHR stuff
    var req = new XMLHttpRequest();
    req.open('GET', url);

    req.onload = function() {
      // This is called even on 404 etc
      // so check the status
      if (req.status == 200) {
        // Resolve the promise with the response text
        resolve(req.response);
      }
      else {
        // Otherwise reject with the status text
        // which will hopefully be a meaningful error
        reject(Error(req.statusText));
      }
    };

    // Handle network errors
    req.onerror = function() {
      reject(Error("Network Error"));
    };

    // Make the request
    req.send();
  });
}
```

Now let's use it:

```js
get('story.json').then(function(response) {
  console.log("Success!", response);
}, function(error) {
  console.error("Failed!", error);
})
```

Now we can make HTTP requests without manually typing `XMLHttpRequest`, which is great, because the
less I have to see the infuriating camel-casing of `XMLHttpRequest`, the happier my life will be.

## Chaining

`then()` isn't the end of the story, you can chain `then`s together to
transform values or run additional async actions one after another.

### Transforming values

You can transform values simply by returning the new value:

```js
var promise = new Promise(function(resolve, reject) {
  resolve(1);
});

promise.then(function(val) {
  console.log(val); // 1
  return val + 2;
}).then(function(val) {
  console.log(val); // 3
})
```

As a practical example, let's go back to:

```js
get('story.json').then(function(response) {
  console.log("Success!", response);
})
```

The response is JSON, but we're currently receiving it as plain text. We
could alter our get function to use the JSON
[`responseType`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#responseType),
but we could also solve it in promises land:

```js
get('story.json').then(function(response) {
  return JSON.parse(response);
}).then(function(response) {
  console.log("Yey JSON!", response);
})
```

Since `JSON.parse()` takes a single argument and returns a transformed value,
we can make a shortcut:

```js
get('story.json').then(JSON.parse).then(function(response) {
  console.log("Yey JSON!", response);
})
```

In fact, we could make a `getJSON()` function really easily:

```js
function getJSON(url) {
  return get(url).then(JSON.parse);
}
```

`getJSON()` still returns a promise, one that fetches a url then parses
the response as JSON.

### Queuing asynchronous actions

You can also chain `then`s to run async actions in sequence.

When you return something from a `then()` callback, it's a bit magic.
If you return a value, the next `then()` is called with that value. However,
if you return something promise-like, the next `then()` waits on it, and is
only called when that promise settles (succeeds/fails). For example:

```js
getJSON('story.json').then(function(story) {
  return getJSON(story.chapterUrls[0]);
}).then(function(chapter1) {
  console.log("Got chapter 1!", chapter1);
})
```

Here we make an async request to `story.json`, which gives us a set of
URLs to request, then we request the first of those. This is when promises
really start to stand out from simple callback patterns.

You could even make a shortcut method to get chapters:

```js
var storyPromise;

function getChapter(i) {
  storyPromise = storyPromise || getJSON('story.json');

  return storyPromise.then(function(story) {
    return getJSON(story.chapterUrls[i]);
  })
}

// and using it is simple:
getChapter(0).then(function(chapter) {
  console.log(chapter);
  return getChapter(1);
}).then(function(chapter) {
  console.log(chapter);
})
```

We don't download `story.json` until `getChapter` is called, but the next
time(s) `getChapter` is called we reuse the story promise, so `story.json`
is only fetched once. Yay Promises!

## Error handling

As we saw earlier, `then()` takes two arguments, one for success, one
for failure (or fulfill and reject, in promises-speak):

```js
get('story.json').then(function(response) {
  console.log("Success!", response);
}, function(error) {
  console.log("Failed!", error);
})
```

You can also use `catch()`:

```js
get('story.json').then(function(response) {
  console.log("Success!", response);
}).catch(function(error) {
  console.log("Failed!", error);
})
```

There's nothing special about `catch()`, it's just sugar for
`then(undefined, func)`, but it's more readable. Note that the two code
examples above do not behave the same, the latter is equivalent to:

```js
get('story.json').then(function(response) {
  console.log("Success!", response);
}).then(undefined, function(error) {
  console.log("Failed!", error);
})
```

The difference is subtle, but extremely useful. Promise rejections skip
forward to the next `then()` with a rejection callback (or `catch()`, since
it's equivalent). With `then(func1, func2)`, `func1` or `func2` will be
called, never both. But with `then(func1).catch(func2)`, both will be
called if `func1` rejects, as they're separate steps in the chain. Take
the following:

```js
asyncThing1().then(function() {
  return asyncThing2();
}).then(function() {
  return asyncThing3();
}).catch(function(err) {
  return asyncRecovery1();
}).then(function() {
  return asyncThing4();
}, function(err) {
  return asyncRecovery2();
}).catch(function(err) {
  console.log("Don't worry about it");
}).then(function() {
  console.log("All done!");
})
```

The flow above is very similar to normal JavaScript try/catch, errors that
happen within a "try" go immediately to the `catch()` block. Here's the
above as a flowchart (because I love flowcharts):

Follow the blue lines for promises that fulfill, or the red for ones that
reject.

### JavaScript exceptions and promises

Rejections happen when a promise is explicitly rejected, but also implicitly
if an error is thrown in the constructor callback:

```js
var jsonPromise = new Promise(function(resolve, reject) {
  // JSON.parse throws an error if you feed it some
  // invalid JSON, so this implicitly rejects:
  resolve(JSON.parse("This ain't JSON"));
});

jsonPromise.then(function(data) {
  // This never happens:
  console.log("It worked!", data);
}).catch(function(err) {
  // Instead, this happens:
  console.log("It failed!", err);
})
```

This means it's useful to do all your promise-related work inside the
promise constructor callback, so errors are automatically caught and
become rejections.

The same goes for errors thrown in `then()` callbacks.

```js
get('/').then(JSON.parse).then(function() {
  // This never happens, '/' is an HTML page, not JSON
  // so JSON.parse throws
  console.log("It worked!", data);
}).catch(function(err) {
  // Instead, this happens:
  console.log("It failed!", err);
})
```

### Error handling in practice

With our story and chapters, we can use catch to display an error to the user:

```js
getJSON('story.json').then(function(story) {
  return getJSON(story.chapterUrls[0]);
}).then(function(chapter1) {
  addHtmlToPage(chapter1.html);
}).catch(function() {
  addTextToPage("Failed to show chapter");
}).then(function() {
  document.querySelector('.spinner').style.display = 'none';
})
```

If fetching `story.chapterUrls[0]` fails (e.g., http 500 or user is offline),
it'll skip all following success callbacks, which includes the one in
`getJSON()` which tries to parse the response as JSON, and also skips the
callback that adds chapter1.html to the page. Instead it moves onto the catch
callback. As a result, "Failed to show chapter" will be added to the page if
any of the previous actions failed.

Like JavaScript's try/catch, the error is caught and subsequent code
continues, so the spinner is always hidden, which is what we want. The
above becomes a non-blocking async version of:

```js
try {
  var story = getJSONSync('story.json');
  var chapter1 = getJSONSync(story.chapterUrls[0]);
  addHtmlToPage(chapter1.html);
}
catch (e) {
  addTextToPage("Failed to show chapter");
}
document.querySelector('.spinner').style.display = 'none'
```

You may want to `catch()` simply for logging purposes, without recovering
from the error. To do this, just rethrow the error. We could do this in
our `getJSON()` method:

```js
function getJSON(url) {
  return get(url).then(JSON.parse).catch(function(err) {
    console.log("getJSON failed for", url, err);
    throw err;
  });
}
```

So we've managed to fetch one chapter, but we want them all. Let's make
that happen.

## Parallelism and sequencing: getting the best of both

Thinking async isn't easy. If you're struggling to get off the mark,
try writing the code as if it were synchronous. In this case:

```js
try {
  var story = getJSONSync('story.json');
  addHtmlToPage(story.heading);

  story.chapterUrls.forEach(function(chapterUrl) {
    var chapter = getJSONSync(chapterUrl);
    addHtmlToPage(chapter.html);
  });

  addTextToPage("All done");
}
catch (err) {
  addTextToPage("Argh, broken: " + err.message);
}

document.querySelector('.spinner').style.display = 'none'
```

{% Glitch {
  id: 'promises-sync-example',
  height: 480
} %}

That works! But it's sync and locks up the browser while things download. To
make this work async we use `then()` to make things happen one after another.

```js
getJSON('story.json').then(function(story) {
  addHtmlToPage(story.heading);

  // TODO: for each url in story.chapterUrls, fetch & display
}).then(function() {
  // And we're all done!
  addTextToPage("All done");
}).catch(function(err) {
  // Catch any error that happened along the way
  addTextToPage("Argh, broken: " + err.message);
}).then(function() {
  // Always hide the spinner
  document.querySelector('.spinner').style.display = 'none';
})
```

But how can we loop through the chapter urls and fetch them in order? This
**doesn't work**:

```js
story.chapterUrls.forEach(function(chapterUrl) {
  // Fetch chapter
  getJSON(chapterUrl).then(function(chapter) {
    // and add it to the page
    addHtmlToPage(chapter.html);
  });
})
```

`forEach` isn't async-aware, so our chapters would appear in whatever order
they download, which is basically how Pulp Fiction was written. This isn't
Pulp Fiction, so let's fix it.

### Creating a sequence

We want to turn our `chapterUrls` array into a sequence of promises. We can do that using `then()`:

```js
// Start off with a promise that always resolves
var sequence = Promise.resolve();

// Loop through our chapter urls
story.chapterUrls.forEach(function(chapterUrl) {
  // Add these actions to the end of the sequence
  sequence = sequence.then(function() {
    return getJSON(chapterUrl);
  }).then(function(chapter) {
    addHtmlToPage(chapter.html);
  });
})
```

This is the first time we've seen `Promise.resolve()`, which creates a
promise that resolves to whatever value you give it. If you pass it an
instance of `Promise` it'll simply return it (**note:** this is a
change to the spec that some implementations don't yet follow). If you
pass it something promise-like (has a `then()` method), it creates a
genuine `Promise` that fulfills/rejects in the same way. If you pass
in any other value, e.g., `Promise.resolve('Hello')`, it creates a
promise that fulfills with that value. If you call it with no value,
as above, it fulfills with "undefined".

There's also `Promise.reject(val)`, which creates a promise that rejects with
the value you give it (or undefined).

We can tidy up the above code using
[`array.reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce):

```js
// Loop through our chapter urls
story.chapterUrls.reduce(function(sequence, chapterUrl) {
  // Add these actions to the end of the sequence
  return sequence.then(function() {
    return getJSON(chapterUrl);
  }).then(function(chapter) {
    addHtmlToPage(chapter.html);
  });
}, Promise.resolve())
```

This is doing the same as the previous example, but doesn't need the separate
"sequence" variable. Our reduce callback is called for each item in the array.
"sequence" is `Promise.resolve()` the first time around, but for the rest of the
calls "sequence" is whatever we returned from the previous call. `array.reduce`
is really useful for boiling an array down to a single value, which in this case
is a promise.

Let's put it all together:

```js
getJSON('story.json').then(function(story) {
  addHtmlToPage(story.heading);

  return story.chapterUrls.reduce(function(sequence, chapterUrl) {
    // Once the last chapter's promise is done…
    return sequence.then(function() {
      // …fetch the next chapter
      return getJSON(chapterUrl);
    }).then(function(chapter) {
      // and add it to the page
      addHtmlToPage(chapter.html);
    });
  }, Promise.resolve());
}).then(function() {
  // And we're all done!
  addTextToPage("All done");
}).catch(function(err) {
  // Catch any error that happened along the way
  addTextToPage("Argh, broken: " + err.message);
}).then(function() {
  // Always hide the spinner
  document.querySelector('.spinner').style.display = 'none';
})
```

{% Glitch {
  id: 'promises-async-example',
  height: 480
} %}

And there we have it, a fully async version of the sync version. But we can do
better. At the moment our page is downloading like this:

  <video controls autoplay loop muted class="w-screenshot">
    <source src="https://storage.googleapis.com/web-dev-assets/promises/promise1.webm" type="video/webm; codecs=vp8">
    <source src="https://storage.googleapis.com/web-dev-assets/promises/promise1.mp4" type="video/mp4; codecs=h264">
  </video>

Browsers are pretty good at downloading multiple things at once, so we're losing
performance by downloading chapters one after the other. What we want to do is
download them all at the same time, then process them when they've all arrived.
Thankfully there's an API for this:

```js
Promise.all(arrayOfPromises).then(function(arrayOfResults) {
  //...
})
```

`Promise.all` takes an array of promises and creates a promise that fulfills
when all of them successfully complete. You get an array of results (whatever
the promises fulfilled to) in the same order as the promises you passed in.

```js
getJSON('story.json').then(function(story) {
  addHtmlToPage(story.heading);

  // Take an array of promises and wait on them all
  return Promise.all(
    // Map our array of chapter urls to
    // an array of chapter json promises
    story.chapterUrls.map(getJSON)
  );
}).then(function(chapters) {
  // Now we have the chapters jsons in order! Loop through…
  chapters.forEach(function(chapter) {
    // …and add to the page
    addHtmlToPage(chapter.html);
  });
  addTextToPage("All done");
}).catch(function(err) {
  // catch any error that happened so far
  addTextToPage("Argh, broken: " + err.message);
}).then(function() {
  document.querySelector('.spinner').style.display = 'none';
})
```

{% Glitch {
  id: 'promises-async-all-example',
  height: 480
} %}

Depending on connection, this can be seconds faster than loading one-by-one,
and it's less code than our first try. The chapters can download in whatever
order, but they appear on screen in the right order.

  <video controls autoplay loop muted class="w-screenshot">
    <source src="https://storage.googleapis.com/web-dev-assets/promises/promise2.webm" type="video/webm; codecs=vp8">
    <source src="https://storage.googleapis.com/web-dev-assets/promises/promise2.mp4" type="video/mp4; codecs=h264">
  </video>

However, we can still improve perceived performance. When chapter one arrives we
should add it to the page. This lets the user start reading before the rest of
the chapters have arrived. When chapter three arrives, we wouldn't add it to the
page because the user may not realize chapter two is missing. When chapter two
arrives, we can add chapters two and three, etc etc.

To do this, we fetch JSON for all our chapters at the same time, then create a
sequence to add them to the document:

```js
getJSON('story.json')
.then(function(story) {
  addHtmlToPage(story.heading);

  // Map our array of chapter urls to
  // an array of chapter json promises.
  // This makes sure they all download in parallel.
  return story.chapterUrls.map(getJSON)
    .reduce(function(sequence, chapterPromise) {
      // Use reduce to chain the promises together,
      // adding content to the page for each chapter
      return sequence
      .then(function() {
        // Wait for everything in the sequence so far,
        // then wait for this chapter to arrive.
        return chapterPromise;
      }).then(function(chapter) {
        addHtmlToPage(chapter.html);
      });
    }, Promise.resolve());
}).then(function() {
  addTextToPage("All done");
}).catch(function(err) {
  // catch any error that happened along the way
  addTextToPage("Argh, broken: " + err.message);
}).then(function() {
  document.querySelector('.spinner').style.display = 'none';
})
```

{% Glitch {
  id: 'promises-async-best-example',
  height: 480
} %}

And there we go, the best of both! It takes the same amount of time to deliver
all the content, but the user gets the first bit of content sooner.

  <video controls autoplay loop muted class="w-screenshot">
    <source src="https://storage.googleapis.com/web-dev-assets/promises/promise3.webm" type="video/webm; codecs=vp8">
    <source src="https://storage.googleapis.com/web-dev-assets/promises/promise3.mp4" type="video/mp4; codecs=h264">
  </video>

In this trivial example, all of the chapters arrive around the same time, but
the benefit of displaying one at a time will be exaggerated with more, larger
chapters.

Doing the above with [Node.js-style callbacks or
events](https://gist.github.com/jakearchibald/0e652d95c07442f205ce) is around
double the code, but more importantly isn't as easy to follow. However, this
isn't the end of the story for promises, when combined with other ES6 features
they get even easier.

## Bonus round: expanded capabilities

Since I originally wrote this article, the ability to use Promises has expanded
greatly. Since Chrome 55, async functions have allowed promise-based code to be
written as if it were synchronous, but without blocking the main thread. You can
read more about that in [my async functions article](/async-functions). There's
widespread support for both Promises and async functions in the major browsers.
You can find the details in MDN's
[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
and [async
function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
reference.

Many thanks to Anne van Kesteren, Domenic Denicola, Tom Ashworth, Remy Sharp,
Addy Osmani, Arthur Evans, and Yutaka Hirano who proofread this and made
corrections/recommendations.

Also, thanks to [Mathias Bynens](https://mathiasbynens.be/) for
[updating various parts](https://github.com/html5rocks/www.html5rocks.com/pull/921/files)
of the article.


text:
---
layout: post
title: Information flow
---
As I took using of excellent [Obsidian](https://obsidian.md) project, I'm trying to go from data -> insights. But a
lot of times actually it's more toying with technologies than actually focusing on benefits. So the image above fits
quite well with what I feel.

![Image](/images/dcf07e6a-7b8f-4329-a382-ceed151c4d15_750x751.webp)


text:
---
layout: post
title: "Generalized linear mixing model accounting for endmember variability"
date: 2017-10-20 22:46:12
categories: arXiv_CV
tags: arXiv_CV
author: Tales Imbiriba, Ricardo Augusto Borsoi, José Carlos Moreira Bermudez
mathjax: true
---

* content
{:toc}

##### Abstract
Endmember variability is an important factor for accurately unveiling vital information relating the pure materials and their distribution in hyperspectral images. Recently, the extended linear mixing model (ELMM) has been proposed as a modification of the linear mixing model (LMM) to consider endmember variability effects resulting mainly from illumination changes. In this paper, we further generalize the ELMM leading to a new model (GLMM) to account for more complex spectral distortions where different wavelength intervals can be affected unevenly. We also extend the existing methodology to jointly estimate the variability and the abundances for the GLMM. Simulations with real and synthetic data show that the unmixing process can benefit from the extra flexibility introduced by the GLMM.

##### Abstract (translated by Google)
端元变异性是精确揭示与高光谱图像中纯物质及其分布有关的重要信息的重要因素。最近，已经提出扩展线性混合模型（ELMM）作为线性混合模型（LMM）的修改以考虑主要由照明变化引起的端元变异效应。在本文中，我们进一步推广ELMM，导致一个新的模型（GLMM），以解决不同的波长间隔可能受到不均匀影响的更复杂的光谱失真。我们还扩展了现有的方法来共同估计GLMM的变化性和丰度。使用真实和合成数据进行的仿真表明，解混过程可以从GLMM引入的额外的灵活性中受益。

##### URL
[https://arxiv.org/abs/1710.07723](https://arxiv.org/abs/1710.07723)

##### PDF
[https://arxiv.org/pdf/1710.07723](https://arxiv.org/pdf/1710.07723)


text:
erlpy_port
======
TCP Server Socket written in Erlang and execute python code through Erlang port.

How it works?
------
The gen_server (erlpy_port.erl) creates one child (gen_server - erlpy_port_acceptor.erl) to listening a TCP connection. When a client establishes a connection to the child that was listening, erlpy_port creates another child to listening again. The child has a timeout to receive some message, if the timeout ends, this child die and close the TCP connection.

The child receives a message that included an ID. This ID is associated with a python file, this association is defined in erlpy_port.schema and then, this child opens a port and execute that file. Finally, this child collects the response by the python file and returns that response to the client.

The message received and sent is a json string format.

Dependencies
------
You will need:

Erlang OTP 18.0  or later

Python 2.7.12 or later

rebar3 to compile

Clone
------

Clone:

	$ git clone https://github.com/enriqueGuerrero/erlpy_port.git

Into erlpy_port:

	$ cd erlpy_port

Compile:

	$ make compile

How to configure?
------

See schema/erlpy_port.schema file.

Starting
------
To start erlpy_port, type:

	$ make start

Or you also can:

	$ make console

Author
------
Enrique Iván Guerrero Martínez<EMAIL_ADDRESS>
License
------
THIS SOFTWARE IS LICENSED UNDER BSD LICENSE.


text:
<!--
Copyright 2018 Province of British Columbia

This work is licensed under the Creative Commons Attribution 4.0 International License.
To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.
-->

# shinyapps.io

The shinyapps.io service offered by RStudio is an option for deploying your BC Government shiny app, but only if it meets some important criteria:

* open data, listed in the B.C. Government's open data catalogue [catalogue.data.gov.bc.ca](https://catalogue.data.gov.bc.ca/dataset?download_audience=Public)

- related to this, you will require a Privacy Impact Assessment for your app, which will state that the data are licensed under the Open License

* open code, posted to a repo within [github.com/bcgov](https://github.com/bcgov)

* a bcgov subscription with [shinyapps.io](https://www.shinyapps.io/)

A Strategic Threat Risk Assessment has been completed for shinyapps.io. Please contact<EMAIL_ADDRESS>for a copy.

Below are more details regarding these elements.

---

### Open Data

* the B.C. Government [Open Data Initiative](https://www2.gov.bc.ca/gov/content/data/open-data): information about Open Government License, the Open Information and Open Data Policy, etc

### Posting your code to GitHub

* the B.C. [Policy Framework for GitHub](https://github.com/bcgov/BC-Policy-Framework-For-GitHub)

### Other

-30-

repository: bcgov/bcgov-Shiny-deployment-paths

repo_name: bcgov/bcgov-Shiny-deployment-paths


text:
# Summary
This logic is a simple socket which supports the states `on` and `off`.

# Configuration

Example:

```json
{
    "config": {
        "initial_state": "off" // on or off (default)
    }
}
```

gha_language: Python


text:
# Sharing files and folders

Files in SharePoint live inside libraries and possibly inside a folder structure inside the library. When you want to share a file, folder or library with other users you can use the PnP Core SDK Sharing support.

In the remainder of this article you'll see a lot of `context` use: in this case this is a `PnPContext` which was obtained via the `PnPContextFactory` as explained in the [overview article](readme.md) and show below:

```csharp
using (var context = await pnpContextFactory.CreateAsync("SiteToWorkWith"))
{
    // See next chapter on how to use the PnPContext for working with lists
}
```

## Scoping the "share"

When you share content you often just want to share what's really needed, oversharing content is never a good idea. When using the share features in PnP Core SDK you can either share:

- A single list item (`IListItem`) (see [here](./sharing-listitems.md) for more details)
- A single file (`IFile`)
- A single folder and all the contents inside that folder (`IFolder`). Note that to share the contents of a complete library you can use the `IList.RootFolder` property as sharing target

> [!Important]
> In the remainder of the chapter the samples will show sharing of a `IFile`, but sharing of an `IFolder` works identically the same.

After selecting what to share the next step is providing information about with whom you're sharing and how the sharing will be configured. To what extend you can configure all of this depends on the external sharing settings configured for your tenant. Navigate to your **SharePoint admin center**, click **Policies** in the left navigation and select **Sharing** to see the tenant sharing configuration. In order to for example share a file with a new guest user the external sharing for SharePoint/OneDrive must be set to the "New and existing guests" level or higher.

Next to the sharing configuration and tenant level there are also sharing settings at site collection level as certain site collections can be configured with more restrictive sharing policies versus the tenant. If you're using the PnP Core SDK sharing API and you're running into issues then ensure the site collection sharing settings are set correctly. Navigate to your **SharePoint admin center**, click **Sites** in the left navigation and select **Active sites**. In the list of site collections find the one you want to share and verify, select it and the click on the **...** and pick **Sharing** to open the site collection sharing settings.

> [!Note]
> You can also programmatically verify and alter site collection sharing settings via the [PnP Core SDK Admin component](https://pnp.github.io/pnpcore/using-the-sdk/admin-sharepoint-sites.html#getting-and-setting-site-collection-properties).

## Get current shares for a folder or file

To list the shares defined on a folder or file you can use one of the `GetShareLinks` methods. These methods return an `IGraphPermissionCollection` containing one `IGraphPermission` row per configured share.

```csharp
// Assume this file has some shared defined
var file = await context.Web.GetFileByServerRelativeUrlAsync("/sites/demo/docs/fileA.docx");
var sharingLinks = await file.GetShareLinksAsync();
foreach(var share in sharingLinks)
{
    // Do something with the share
}
```

## Sharing content with your organization

To share content within your tenant (your organization) you need to use one of the `CreateOrganizationalSharingLink` methods in combination with a configured `OrganizationalLinkOptions` instance. The only property to set here is the `Type` of share: do you want to enable people in your organization to view the shared content or also edit the content?

```csharp
var file = await context.Web.GetFileByServerRelativeUrlAsync("/sites/demo/docs/fileA.docx");
var shareLinkRequestOptions = new OrganizationalLinkOptions()
{
    Type = ShareType.Edit
};

// Grant everyone in the organization edit permissions on the file
var share = await file.CreateOrganizationalSharingLinkAsync(shareLinkRequestOptions);
```

## Share content with certain users

If you want to selectively share content with one or more users you can use one of the `CreateUserSharingLink` methods in combination with a configured `UserLinkOptions` instance. Key properties to set are the `Recipients` (people you're sharing to) and `Type` of share. Below example shows this:

```csharp
var file = await context.Web.GetFileByServerRelativeUrlAsync("/sites/demo/docs/fileA.docx");

// List of users to share the file/folder with
var driveRecipients = new List<IDriveRecipient>()
{
    UserLinkOptions.CreateDriveRecipient("linda@contoso.onmicrosoft.com"),
<EMAIL_ADDRESS>
};

var shareLinkRequestOptions = new UserLinkOptions()
{
    // Users can see and edit the file online, but not download it
    Type = ShareType.BlocksDownload,
    Recipients = driveRecipients
};

var share = await file.CreateUserSharingLinkAsync(shareLinkRequestOptions);
```

## Share content with everyone (anonymous sharing)

If your tenant and site settings allow it you can also share content anonymously so that everyone having the link can access the content. Doing so requires using one of the `CreateAnonymousSharingLink` methods together with a configured `AnonymousLinkOptions` instance. Key properties to set are the `Type` of share, a `Password` for consuming the sharing link and `ExpirationDateTime` defining how long the anonymous share will stay valid. Below example shows this:

```csharp
var file = await context.Web.GetFileByServerRelativeUrlAsync("/sites/demo/docs/fileA.docx");

var shareLinkRequestOptions = new AnonymousLinkOptions()
{
    Type = ShareType.View,
    Password = "PnP Rocks!",
    ExpirationDateTime = DateTime.Now.AddDays(5)
};

var share = await file.CreateAnonymousSharingLinkAsync(shareLinkRequestOptions);
```

## Share content via an invite

While above share methods do directly share the content with the user(s), there's also an option to share via inviting users to a file or folder. This can be done using one of the `CreateSharingInvite` methods in combination with an `InviteOptions` instance.

```csharp
var file = await context.Web.GetFileByServerRelativeUrlAsync("/sites/demo/docs/fileA.docx");

var driveRecipients = new List<IDriveRecipient>()
{
<EMAIL_ADDRESS>};

var shareRequestOptions = new InviteOptions()
{
    Message = "I'd like to share this file with you",
    RequireSignIn = true,
    SendInvitation = true,
    Recipients = driveRecipients,
    Roles = new List<PermissionRole> { PermissionRole.Read },
    ExpirationDateTime = DateTime.Now.AddDays(5)
};

var share = await file.CreateSharingInviteAsync(shareRequestOptions);
```

## Update file shares

When you've created a sharing link granting access to users you can still make changes to it by adding or removing users. Once you've a reference to a sharing link use the `GrantUserPermissions` and `RemoveUserPermissions` methods to update the users that get access via this sharing link.

```csharp
var file = await context.Web.GetFileByServerRelativeUrlAsync("/sites/demo/docs/fileA.docx");

// Get the first sharing link for this file
var sharingLink = await file.GetShareLinksAsync().First();

// Define the new set users that need to get access
var driveRecipientsToAdd = new List<IDriveRecipient>()
{
    UserLinkOptions.CreateDriveRecipient("linda@contoso.onmicrosoft.com"),
<EMAIL_ADDRESS>
};

// Add the new users
await sharingLink.GrantUserPermissionsAsync(driveRecipientsToAdd);

//Define the users to remove
var driveRecipientsToRemove = new List<IDriveRecipient>()
{
<EMAIL_ADDRESS>};

// Remove user from sharing link
await sharingLink.RemoveUserPermissionsAsync(driveRecipientsToRemove);
```

## Deleting file shares

There are two options to delete sharing links for a file or folder: you can either delete all sharing links for a given file/folder or you can enumerate the current sharing links and delete a specific one. To delete all sharing links you can use one of the `DeleteShareLinks` methods, to delete an individual sharing link you first need to load the sharing links via one of the `GetShareLinks` methods followed by using one of the `DeletePermission` links on the returned `IGraphPermission` instance. Below code sample shows both approaches.

```csharp
var file = await context.Web.GetFileByServerRelativeUrlAsync("/sites/demo/docs/fileA.docx");

// Option A: delete all shares of the file/folder
await file.DeleteShareLinksAsync();

// Option B: delete specific shares of the file/folder
var sharingLinks = await file.GetShareLinksAsync();
foreach(var share in sharingLinks)
{
    // Let's imagine we're deleting all shares that are secured via password
    if (share.HasPassword)
    {
        await share.DeletePermissionAsync();
    }
}
```

repository: pnp/pnpcore

branch_name: refs/heads/dev

gha_language: C#

repo_name: pnp/pnpcore


text:
---
layout: post
title: "Ruby Debugging Magic Cheat Sheet"
date: 2016-01-25
published: true
author_name: Richard Schneeman
author_url: https://twitter.com/schneems
---

This document is all about deciphering behavior of Ruby code using nothing but Ruby code. I recommend you get familiar with a debugger like [pry-debugger](https://github.com/nixme/pry-debugger), this doc doesn't go into debuggers [because they're not always available](https://www.reddit.com/r/ruby/comments/42lxrq/ruby_debugging_magic_cheat_sheet/czbef0m).

Many of these techniques are pulled from my first popular talk [Dissecting Ruby with Ruby](https://www.youtube.com/watch?v=UYVUSoNrM-c).

> This page is open source and a living document, send suggestions in PR form to [my blog on GitHub](https://github.com/schneems/schneems/blob/master/_posts/2016-01-25-ruby-debugging-magic-cheat-sheet.md).

Unless otherwise stated, all techniques work for the last major release of Ruby.

## Figure out where a method was defined

```ruby
object = Object.new
puts object.method(:blank?).source_location
=> ["/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/object/blank.rb", 14]
```

This method was defined on line `14` of the file `active_support/core_ext/object/blank.rb`.

## Opening a dependency from a project

```sh
$ bundle open active_support
```

This will open the version of `active_support` you have in your `Gemfile.lock`. From here you can add debugging statements.

This command will use the value in your `EDITOR` environment variable. The default is vi or something. You can set this in your `.bashrc` file. For example I use Sublime text and have this in my `.bashrc`

```sh
export EDITOR="subl -w"
```

Google for the appropriate invocation for your editor.

If you close the file accidentally you can use `gem pristine` which is discussed below.

## See where an object was created

You can use object space to see where a constant or an object was created.

```ruby
require 'objspace'
ObjectSpace.trace_object_allocations_start

Kernel.send(:define_method, :sup) do |obj|
  puts "#{ ObjectSpace.allocation_sourcefile(obj) }:#{ ObjectSpace.allocation_sourceline(obj) }"
end

world = "hello"

sup world
# => /tmp/scratch.rb:10
```

Since the invocation to get the file and line number is so long, I added a helper method `sup`. Make sure tracing is started early as possible, I usually put this code in the top of my Gemfile. Remove this code when you're not debugging, tracing allocations has a performance impact.

If you find yourself on a remote machine without access to an editor you can [inject this into a Gemfile in a few lines of bash](https://gist.github.com/schneems/003de3b80e6b983c84ebc7273fd60947)

Thanks to [Aaron's "I need to find where this object came from"](https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html#i-need-to-find-where-this-object-came-from).

## Figuring out how a method was called

To generate a backtrace without raising an exception use the `caller` method like:

```ruby
class Project

  def foo
    puts "====================="
    puts caller
  end
end
```

Now when you generate a request you'll get a backtrace like:

```sh
=====================
/Users/richardschneeman/documents/projects/my_rails_app/app/controllers/projects_controller.rb:18:in `new'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/abstract_controller/base.rb:183:in `process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal/rendering.rb:30:in `process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:126:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:455:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:90:in `run_callbacks'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/abstract_controller/callbacks.rb:19:in `process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal/rescue.rb:27:in `process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/notifications.rb:164:in `instrument'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activerecord-5.0.0.beta1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/abstract_controller/base.rb:128:in `process'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionview-5.0.0.beta1/lib/action_view/rendering.rb:30:in `process'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal.rb:192:in `dispatch'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/metal.rb:264:in `dispatch'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/routing/route_set.rb:32:in `serve'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/journey/router.rb:42:in `block in serve'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/journey/router.rb:29:in `each'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/journey/router.rb:29:in `serve'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/routing/route_set.rb:715:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionview-5.0.0.beta1/lib/action_view/digestor.rb:14:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/rack-2.0.0.alpha/lib/rack/etag.rb:25:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/rack-2.0.0.alpha/lib/rack/conditional_get.rb:25:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/rack-2.0.0.alpha/lib/rack/head.rb:12:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/rack-2.0.0.alpha/lib/rack/session/abstract/id.rb:220:in `context'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/rack-2.0.0.alpha/lib/rack/session/abstract/id.rb:214:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/cookies.rb:608:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activerecord-5.0.0.beta1/lib/active_record/query_cache.rb:36:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activerecord-5.0.0.beta1/lib/active_record/connection_adapters/abstract/connection_pool.rb:963:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activerecord-5.0.0.beta1/lib/active_record/migration.rb:524:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:97:in `__run_callbacks__'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/callbacks.rb:90:in `run_callbacks'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/reloader.rb:71:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/web-console-3.0.0/lib/web_console/middleware.rb:27:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/railties-5.0.0.beta1/lib/rails/rack/logger.rb:42:in `call_app'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/railties-5.0.0.beta1/lib/rails/rack/logger.rb:24:in `block in call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/tagged_logging.rb:70:in `block in tagged'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/tagged_logging.rb:70:in `tagged'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/railties-5.0.0.beta1/lib/rails/rack/logger.rb:24:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/request_id.rb:24:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/rack-2.0.0.alpha/lib/rack/method_override.rb:22:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/rack-2.0.0.alpha/lib/rack/runtime.rb:22:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/load_interlock.rb:13:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_dispatch/middleware/static.rb:132:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/rack-2.0.0.alpha/lib/rack/sendfile.rb:111:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/railties-5.0.0.beta1/lib/rails/engine.rb:522:in `call'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/puma-2.15.3/lib/puma/server.rb:541:in `handle_request'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/puma-2.15.3/lib/puma/server.rb:388:in `process_client'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/puma-2.15.3/lib/puma/server.rb:270:in `block in run'
/Users/richardschneeman/.gem/ruby/2.3.0/gems/puma-2.15.3/lib/puma/thread_pool.rb:106:in `block in spawn_thread'
```

Ugh, long ugly backtrace. What does it mean? The top line is the last method that was run before our, `puts caller` was called. In this case

```sh
/Users/richardschneeman/documents/projects/my_rails_app/app/controllers/projects_controller.rb:18:in `new'
```

This was called from the `projects_controller` line 18, in the `new` method in my app. We can trace this back all the way to the beginning of the request by looking at the first line

```sh
/Users/richardschneeman/.gem/ruby/2.3.0/gems/puma-2.15.3/lib/puma/thread_pool.rb:106:in `block in spawn_thread'
```

This is where Puma instantiated the request.

If you work from the bottom of the backtrace and go up, you can see exactly how Puma turns a request into code.

## Find which method Super is Calling

Let's say you have code that calls `super` you can find where that method is defined like this:

```ruby
def foo
  puts method(:foo).super_method.source_location
  super
end
```

I love this one since I proposed the method 😉. You can read more about `super_method` here: [Debugging Super methods in Ruby 2.2+](https://www.schneems.com/2015/01/14/debugging-super-methods-ruby-22.html).

## List all methods on an object

```ruby
object.methods
# => [:instance_of?, :public_send, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :private_methods, :kind_of?, :instance_variables, :tap, :is_a?, :extend, :define_singleton_method, :to_enum, :enum_for, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :inspect, :display, :send, :object_id, :to_s, :method, :public_method, :singleton_method, :nil?, :hash, :class, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untaint, :untrust, :trust, :untrusted?, :methods, :protected_methods, :frozen?, :public_methods, :singleton_methods, :!, :==, :!=, :__send__, :equal?, :instance_eval, :instance_exec, :__id__]
```

## Get instance method location without an instance

```ruby
User.instance_method(:github_url).source_location
```

## Introspect method arguments

```ruby
def parse(input, skip_code_comments: false, ignore_whitespace: true)
  # do stuff
end
```

```ruby
method(:parse).parameters
#=> [[:req, :input], [:key, :skip_code_comments], [:key, :ignore_whitespace]]
```

Now you can see all available keyword arguments.

## See where an argument is mutated

Often times, I'll instantiate a variable

```ruby
config.thing = { "foo" => "bar" }
```

But later I'll find it was changed, but I don't know where:

```ruby
puts config.thing
# => {"bar" => "THE FOO KEY IS GONE"}
```

You can see where the value of an object was modified by first `freeze`-ing the object:

```
config.thing.freeze
```

Then later if other code modifies the object, an error will be raised:

```
config.thing.delete("foo")

# active_support/concurrency/share_lock.rb:151:in `delete': can't modify frozen Hash (RuntimeError)
#  from active_support/concurrency/share_lock.rb:151:in `yield_shares'
#  from active_support/concurrency/share_lock.rb:79:in `block in stop_exclusive'
```

There are some caveats: In this example the hash is frozen, but the keys and values are not. If you try to modify a key or value, no exception will be raised. If you're trying to freeze a complex object such as a Hash, you'll need to deep freeze it. This technique also won't work for cases where a variable is assigned instead of mutated.

Originally on my "missing pieces" list, TLo documented it [An object is being mutated but I don't know where](https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html#an-object-is-being-mutated-but-i-dont-know-where.).

## Un-debug a gem

If you've opened a gem and added debug statements, but forget to remove them before closing the file: you'll get those debug statements every time you run your program. To reset every gem to its original state you can use `gem pristine`. For example to reset Active Support:

```sh
$ gem pristine activesupport
Restoring gems to pristine condition...
Restored activesupport-3.2.21
Restored activesupport-3.2.22
Restored activesupport-4.0.0
Restored activesupport-4.1.1
Restored activesupport-4.2.0
Restored activesupport-4.2.1
Restored activesupport-4.2.3
Restored activesupport-4.2.5.rc1
Restored activesupport-4.2.5
Restored activesupport-5.0.0.beta1
```

To reset ALL gems you can run:

```sh
$ gem pristine --all
```

> Note: this may take a LONG time, especially if you've got gems with c-extensions.

## Missing Pieces Wish List

> Warning: These things don't exist, but I wish they did. Don't try to use them, they won't work.

Here's a list of things I want to do from time to time, but haven't found a way to yet. Some of these might not be possible due to limitations in the VM. When a "missing piece" is found it is removed from this section and given it's own heading above.

- Find where a variable is over-written with a different value. While we can use the `freeze` trick to see where a value is modified, we won't see when it is replaced.

```ruby
config.thing = { "foo" => "bar" }.freeze

config.thing = nil
# No error is raised as the hash isn't being mutated, the variable is being assigned a different value
```

## Not debugging

These are a few tricks that aren't debugging related, but I've found helpful for understanding how the interpreter works.

### Disassemble Ruby code:

```ruby
code = <<~CODE
  a = 4
  b = 10
  puts a + b
CODE
puts RubyVM::InstructionSequence.compile(code).disasm
```

Generates something like this:

```
== disasm: #<ISeq:<compiled>@<compiled>>================================
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 2] a          [ 1] b
0000 trace            1                                               (   1)
0002 putobject        4
0004 setlocal_OP__WC__0 4
0006 trace            1                                               (   2)
0008 putobject        10
0010 setlocal_OP__WC__0 3
0012 trace            1                                               (   3)
0014 putself
0015 getlocal_OP__WC__0 4
0017 getlocal_OP__WC__0 3
0019 opt_plus         <callinfo!mid:+, argc:1, ARGS_SIMPLE>, <callcache>
0022 opt_send_without_block <callinfo!mid:puts, argc:1, FCALL|ARGS_SIMPLE>, <callcache>
0025 leave
```

repository: schneems/schneems

repo_name: schneems/schneems


text:
# Binary heap

[Link to article](http://www.growingwiththeweb.com/2013/01/data-structure-binary-heap.html)

![Binary heap image](http://2.bp.blogspot.com/-VyCJgmSuiSE/UQNYEZNdWRI/AAAAAAAAMWo/6NDzZLwBTA0/s1600/minheap.png)

repository: HarshHarwani/growing-with-the-web

repo_name: HarshHarwani/growing-with-the-web


text:
# language-detection-machine-learning
Language detector built from scratch to recognize french, english and portuguese.

## About

That was my first Machine Learning project, It was not easy to do. I had to learn a lot of new concepts about Natural Language Processing and Deep Learning. I really loved to create this project because I also learned about a few classification algorithms (between them the Naive Bayes) and was a cool experience.

## Projects created with this algorithm

![My version of Google Translate Language Detection.](https://github.com/luaenrique/language-detection-machine-learning/tree/master/GoogleTradutorProject)

## How it works?

I've created this project using nltk (a python platform) with the Naive Bayes Algorithm.

To generate my dataset I've create two different robots with node.js, the first one collects articles from wikipedia based on a specific language and the another one organize those articles in different files and folders.

My dataset contains approximately 40.000 sentences per language.

## What is the Naive Bayes Algorithm?

When applied to Machine Learning, Naive Bayes Algorithm can be considered a probabilistic algorithm that considers each one of the features are independent. It is good for text classification because the probability of occurence of a word is not dependent of another word.

## Next Steps

I am looking for ways to improve that algorithm as better as possible. I have read about Stemming and Lemmatization and I will probably apply those concepts to a new version of this project.


text:
# GitHub Actions Template

[![CI Status](https://github.com/technote-space/gh-actions-template/workflows/CI/badge.svg)](https://github.com/technote-space/gh-actions-template/actions)
[![codecov](https://codecov.io/gh/technote-space/gh-actions-template/branch/master/graph/badge.svg)](https://codecov.io/gh/technote-space/gh-actions-template)
[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/gh-actions-template/badge)](https://www.codefactor.io/repository/github/technote-space/gh-actions-template)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/gh-actions-template/blob/master/LICENSE)

Template for GitHub actions.

## Table of Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<details>
<summary>Details</summary>

- [Setup](#setup)
  - [yarn](#yarn)
  - [npm](#npm)
- [Workflows](#workflows)
  - [ci.yml](#ciyml)
  - [add-version-tag.yml](#add-version-tagyml)
  - [toc.yml](#tocyml)
  - [issue-opened.yml](#issue-openedyml)
  - [pr-opened.yml](#pr-openedyml)
  - [pr-updated.yml](#pr-updatedyml)
  - [project-card-moved.yml](#project-card-movedyml)
  - [broken-link-check.yml](#broken-link-checkyml)
  - [update-dependencies.yml](#update-dependenciesyml)
  - [add-test-tag.yml](#add-test-tagyml)
  - [Secrets](#secrets)
- [Test release](#test-release)
- [Helpers](#helpers)
- [Author](#author)

</details>
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Setup
### yarn
- `yarn setup`
### npm
- `npm run setup`

## Workflows

Some `workflows` are included by default.

### ci.yml
CI Workflow

1. ESLint
1. Jest
   - Send coverage report to codecov if `CODECOV_TOKEN` is set.
1. Release GitHub Actions
   - if tag is added.
1. Publish package
   - if tag is added and `NPM_AUTH_TOKEN` is set.
1. Publish release
   - if 3 and 4 jobs are succeeded.
1. Notify by slack
   - if workflow is failure

[ACCESS_TOKEN](#access_token) is required.
[SLACK_WEBHOOK_URL](#slack_webhook_url) is required.

### add-version-tag.yml
Add the release tag when pull request is merged.

1. Get next version from commits histories.
   see [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
1. Add tag.
1. Create branch for next version.

[ACCESS_TOKEN](#access_token) is required.

### toc.yml
Create TOC (Table of contents)

[ACCESS_TOKEN](#access_token) is required.

### issue-opened.yml
- Assign the issue to project
   default setting:
   ```
   Project: Backlog
   Column: To do
   ```
- Assign author to issue

### pr-opened.yml
- Assign the PR to project
   default setting:
   ```
   Project: Backlog
   Column: In progress
   ```
   [ACCESS_TOKEN](#access_token) is required.
- Assign author to PR
- Add labels by branch
   [setting](.github/pr-labeler.yml)

### pr-updated.yml
- Add labels by changed files
   [setting](.github/labeler.yml)
- Create PR histories
- Manage PR by release type
   [ACCESS_TOKEN](#access_token) is required.
- Check version in package.json
   [ACCESS_TOKEN](#access_token) is required.
- Check if it can be published to npm
   if `NPM_AUTH_TOKEN` is set

### project-card-moved.yml
Manage labels by moving project cards

### broken-link-check.yml
Check broken link in README

### update-dependencies.yml
Update package dependencies

- schedule
- PR opened, closed
- repository dispatch

### add-test-tag.yml
Add tag for test release

### Secrets
#### ACCESS_TOKEN
[Personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) with the public_repo or repo scope
(repo is required for private repositories)

#### SLACK_WEBHOOK_URL
https://api.slack.com/messaging/webhooks

## Test release
[![technote-space/release-github-actions-cli - GitHub](https://gh-card.dev/repos/technote-space/release-github-actions-cli.svg)](https://github.com/technote-space/release-github-actions-cli)

1. Create `.env`
   Set [Personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line)
   ```dotenv
   token=1234567890abcdef1234567890abcdef12345678
   ```
1. Run `yarn release`
   - Dry run: `yarn release -n`
   - Help: `yarn release -h`

![cli](https://github.com/technote-space/gh-actions-template/raw/images/cli.gif)

Then, you can use your `GitHub Actions` like follows:

```yaml
on: push
name: Test
jobs:
  toc:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: owner/repo@gh-actions
```

## Helpers
[![technote-space/github-action-helper - GitHub](https://gh-card.dev/repos/technote-space/github-action-helper.svg)](https://github.com/technote-space/github-action-helper)

[![technote-space/github-action-test-helper - GitHub](https://gh-card.dev/repos/technote-space/github-action-test-helper.svg)](https://github.com/technote-space/github-action-test-helper)

[![technote-space/filter-github-action - GitHub](https://gh-card.dev/repos/technote-space/filter-github-action.svg)](https://github.com/technote-space/filter-github-action)

## Author
[GitHub (Technote)](https://github.com/technote-space)
[Blog](https://technote.space)

repository: technote-space/gh-actions-template

gha_language: TypeScript

repo_name: technote-space/gh-actions-template


text:
# arch-bootstrap
Bootstrap ArchLinux build

Downloads and extracts the "bootstrap" ArchLinux distribution (used for
initializing an ArchLinux install from an existing Linux installation).

The bootstrap build contains *no* text editors, so it is recommended that
the `base` package is installed, as in the devjump/arch-base image,
however, you are free to install the packages you wish!

Requires Docker 17.05+ to build.

```
docker build -t arch-bootstrap .
```

repository: devjump/arch-bootstrap

repo_name: devjump/arch-bootstrap


text:
# React Sample Youtube search

###Getting Started###
Checkout this repo, install dependencies, then start the gulp process with the following:

```
	> git clone https://github.com/inflex13/react-yt-search.git
	> cd react-yt-search
	> npm install
	> npm start
```

gha_language: JavaScript


text:
---
layout: about
title: About
permalink: /
subtitle: Departmant of Knowledge Technologies, Jožef Stefan Institute. # Address. Contacts. Moto. Etc.

profile:
  align: right
  image: profile.jpg
  image_circular: false # crops the image to make it circular
  address: >

Office 69a

Teslova 30

1000 Ljubljana

Slovenia

news: true  # includes a list of news items
selected_papers: true # includes a list of papers marked as "selected={true}"
social: true  # includes social icons at the bottom of the page
---
I’m a Ph.D. student at Jožef Stefan International Postgraduate School. My academic interests lie primarily in machine learning and data science, but I also enjoy mathematics and computer science. I mostly work on graph learning, representation learning, equation discovery, geometric deep learning, and interpretable machine learning.

I come from Piran, where I finished elementary school (OŠ Cirila Kosmača Piran) and high school (Srednja tehnična šola Koper). I got my bachelor’s degree in mathematics and computer science from the Faculty of Computer and Information Science in Ljubljana and my master’s degree from the same field at the Faculty of Mathematics and Physics in Ljubljana.

In my free time, I like to watch and play sports, mostly volleyball and football (soccer). My biggest achievement in volleyball is the title of national under-18 champions with GO Volley in the 2013/14 season. I also like reading, especially epic fantasy (for example the cosmere universe).

If you want to enquire about my work, a collaboration, or to talk about mutual interests feel free to contact me through email.


text:
# <NativeRouter>

A [`<Router>`](../../../react-router/docs/api/Router.md) for iOS and Android apps built using [React Native](https://facebook.github.io/react-native/).

```js
import { NativeRouter } from 'react-router-native'

<NativeRouter>
  <App/>
</NativeRouter>
```

## getUserConfirmation: func

A function to use to confirm navigation.

```js
import { Alert } from 'react-native'

// This is the default behavior
const getConfirmation = (message, callback) => {
  Alert.alert('Confirm', message, [
    { text: 'Cancel', onPress: () => callback(false) },
    { text: 'OK', onPress: () => callback(true) }
  ])
}

<NativeRouter getUserConfirmation={getConfirmation}/>
```

## keyLength: number

The length of `location.key`. Defaults to 6.

```js
<NativeRouter keyLength={12}/>
```

## children: node

A [single child element](https://facebook.github.io/react/docs/react-api.html#react.children.only) to render.

repository: kentcdodds/react-router

repo_name: kentcdodds/react-router


text:
>![](http://www.easyicon.net/api/resize_png_new.php?id=1174989&size=16)[vhf/free-programming-books](https://github.com/vhf/free-programming-books)

#免费学习资源列表
## 介绍
If you want to find a learning resource, you should definitely check out our site, [Free Learning Resources](http://resrc.io).
And for those who want to learn a computer language, you should check out these books on [reSRC.io](http://resrc.io/list/10/list-of-free-programming-books/) or on [github](/free-programming-books.md).
This list initially was a clone of [stackoverflow - List of Freely Available Programming Books](http://stackoverflow.com/questions/194812/list-of-freely-available-programming-books/392926#392926) by George Stocker. Now updated, with dead links gone and new content.

Moved to GitHub for collaborative updating and for the site mentioned above.

### 新 : 在free-programming-books.md搜索 (and a whole lot more of learning resources)
[resrc.io/search](http://resrc.io/search/)

### 如何贡献
It's [easy](https://github.com/vhf/free-programming-books/wiki/Contribution). Please read [CONTRIBUTING](/CONTRIBUTING.md).
- [Fork](https://help.github.com/articles/fork-a-repo)
- Read the [TODO](/TODO.md) file(Adding new books is our #1 priority, but things like Alphabetizing are important, too.)
- [Edit](https://github.com/vhf/free-programming-books/edit/master/free-programming-books.md) (we prefer multiple small commits rather than one large change)
- [Send a PR](https://help.github.com/articles/using-pull-requests)
- be part of a project that over 28,000 people starred in 8 months. ;)

**Again, unlike other projects, we prefer multiple small commits rather than one large change in a pull request - it's fine to have one PR, but please make sure your title reflects what you're changing**, thanks.

### 如何分享
+ [Share on Twitter](http://twitter.com/home?status=https://github.com/vhf/free-programming-books%0AFree%20Programming%20Books)
+ [Share on Facebook](http://www.facebook.com/sharer/sharer.php?s=100&p[url]=https://github.com/vhf/free-programming-books&p[images][0]=&p[title]=Free%20Programming%20Books&p[summary]=)
+ [Share on Google Plus](https://plus.google.com/share?url=https://github.com/vhf/free-programming-books)
+ [Share on LinkedIn](http://www.linkedin.com/shareArticle?mini=true&url=https://github.com/vhf/free-programming-books&title=Free%20Programming%20Books&summary=&source=)

### 其它语言
+ Azerbaijan: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-az.md)
+ Bulgarian: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-bg.md)
+ 中文: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-zh.md)
+ Czech: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-cs.md)
+ French: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-fr.md) or [site](http://resrc.io/list/33/livres-gratuits-sur-la-programmation/).
    The French list was based on [this](http://progdupeu.pl/forums/sujet/43/une-banque-de-liens) page.
+ German: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-de.md)
+ Greek: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-gr.md)
+ Hungarian: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-hu.md)
+ Indonesian : [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-id.md)
+ Italian: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-it.md)
+ Japanese: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-ja.md)
+ Korean: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-ko.md)
+ Persian/Farsi (Iran): [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-fa_IR.md)
+ Polish: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-pl.md)
+ Portuguese (Brazil): [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-pt_BR.md)
+ Portuguese (Portugal): [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-pt_PT.md)
+ Romanian (Romania): [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-ro.md)
+ Russian: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-ru.md)
+ Slovak: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-sk.md)
+ Spanish: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-es.md)
+ Turkish: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-tr.md)
+ Ukrainian: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-books-ua.md)

### Noticeable lists from [reSRC](http://resrc.io/)
+ Free JavaScript frameworks resources and tutorials: [github](https://github.com/vhf/free-programming-books/blob/master/javascript-frameworks-resources.md) or [site](http://resrc.io/list/18/javascript-frameworks/)

### 交互式编程资源
+ 免费的交互式编程教程: [github](https://github.com/vhf/free-programming-books/blob/master/free-programming-interactive-tutorials-en.md) or [网站](http://resrc.io/list/217/programming-interactive-tutorials/)

### 播客 - 截屏
免费的播客和视频演示:

+ Czech: [github](https://github.com/vhf/free-programming-books/blob/master/free-podcasts-screencasts-cs.md)
+ 英语: [github](https://github.com/vhf/free-programming-books/blob/master/free-podcasts-screencasts-en.md)

### Software Testing Books
+ [Free ebooks about software testing](https://github.com/ligurio/free-software-testing-books)

repository: wohugb/awesome

repo_name: wohugb/awesome


text:
# A Simple Keras + deep learning REST API

This repository contains the code for [*Building a simple Keras + deep learning REST API*](https://blog.keras.io/building-a-simple-keras-deep-learning-rest-api.html), published on the Keras.io blog.

The method covered here is intended to be instructional. It is _not_ meant to be production-level and capable of scaling under heavy load. If you're interested in a more advanced Keras REST API that leverages message queues and batching, [please refer to this tutorial](https://www.pyimagesearch.com/2018/01/29/scalable-keras-deep-learning-rest-api/).

For an _even more advanced version_ that includes deploying a model to production, [refer to this blog post](https://www.pyimagesearch.com/2018/02/05/deep-learning-production-keras-redis-flask-apache/).

## Getting started

I assume you already have Keras (and a supported backend) installed on your system. From there you need to install [Flask](http://flask.pocoo.org/) and [requests](http://docs.python-requests.org/en/master/):

```sh
$ pip install flask gevent requests
```

Next, clone the repo:

```sh
$ git clone https://github.com/jrosebr1/simple-keras-rest-api.git
```

## Starting the Keras server

Below you can see the image we wish to classify, a _dog_, but more specifically a _beagle_:

![dog](dog.jpg)

The Flask + Keras server can be started by running:

```sh
$ python run_keras_server.py
Using TensorFlow backend.
 * Loading Keras model and Flask starting server...please wait until server has fully started
...
 * Running on http://<IP_ADDRESS>:5000
```

You can now access the REST API via `http://<IP_ADDRESS>:5000`.

## Submitting requests to the Keras server

Requests can be submitted via cURL:

```sh
$ curl -X POST -F<EMAIL_ADDRESS>'http://localhost:5000/predict'
{
  "predictions": [
    {
      "label": "beagle",
      "probability": 0.9901360869407654
    },
    {
      "label": "Walker_hound",
      "probability": 0.002396771451458335
    },
    {
      "label": "pot",
      "probability": 0.0013951235450804234
    },
    {
      "label": "Brittany_spaniel",
      "probability": 0.001283277408219874
    },
    {
      "label": "bluetick",
      "probability": 0.0010894243605434895
    }
  ],
  "success": true
}
```

Or programmatically:

```sh
$ python simple_request.py
1. beagle: 0.9901
2. Walker_hound: 0.0024
3. pot: 0.0014
4. Brittany_spaniel: 0.0013
5. bluetick: 0.0011
```

For solving the issue of

>>model.predict ValueError: Tensor Tensor("fc1000/Softmax:0", shape=(?, 1000), dtype=float32) is not an element of this graph.

```
import tensorflow as tf
...
with graph.as_default():
				preds = model.predict(image)
...
def load_model():
    # load the pre-trained Keras model (here we are using a model
    # pre-trained on ImageNet and provided by Keras, but you can
    # substitute in your own networks just as easily)
	global model
	model = ResNet50(weights="imagenet")
	global graph
	graph = tf.get_default_graph()
```


text:
---
layout: post
title: Python Protobuf 'syntax' Error
description: Common Python Protobuf error
author: Nhat Bui
tags: protobuf, protocol buffer, Python, programming, software
category: programming
---

A common error somebody may encounter using Python protobufs on common Linux distros is:

```
TypeError: __init__() got an unexpected keyword argument 'syntax'
```

This is __most likely__ due to the fact that a lot of OSs have an outdated version of the Python protobuf package.
Typically a user may acquire protobuf tools from the OS package manager like

```
sudo apt-get install protobuf-compiler
sudo apt-get install python-protobuf
```

The protobuf compiler will compile a version of the protobuf which has a syntax the python-protobuf, the package that allows you to do `import google.protobuf`, doesn't understand. Specifically, all objects will be passed a `syntax` field to their `__init__` function. Update Python protobuf by visiting the [repo](https://github.com/google/protobuf/releases) and getting the latest version.


text:
# Rspec::Lintable
> Ensure your controllers are returning "valid" Javascript responses

## Usage

```ruby
describe "#show" do
  before { get :show, format: :js }
  it { should be_lintable }
end
```

## Installation

Add the gem to your `test` group of your `Gemfile` and it will automatically be loaded into your RSpec runtime!

```ruby
# Gemfile
gem 'rspec-lintable', group: :test
```

## Configuration

All options and configuration are done via the standard [Jshint .jshintrc](http://www.jshint.com/docs/)
configuration file.

## Contributing

Interested in contributing?  Review the project [contribution guidelines](CONTRIBUTING.md) and get started!

Patches are always welcome and thank you to all [project contributors](https://github.com/wireframe/rspec-lintable/graphs/contributors)!

repository: wireframe/rspec-lintable

repo_name: wireframe/rspec-lintable


text:
---
layout: post
title: "Practical Linux - Part 04 - Other Desktop Environment & SSH (Continue) | 其他桌面环境与SSH(续)"
date: 2014-10-03 01:42:49 +0000
comments: true
categories: [Linux]
keywords: "linux, desktop environment, de, turorial, ssh"
---
{% youtube r_s8O0GtEHc %}
<!-- more -->
- Oct 2 - Other Desktop Environment & SSH (Continue)
  - Other Desktop Environment
    - askubuntu.com/questions/65083/what-kinds-of-desktop-environments-and-shells-are-available
    - (Unity)
    - GNOME
    - Xfce
    - LXDE
    - KDE
    - Cinnamon
  - SSH
    - en.wikipedia.org/wiki/Secure_Shell
    - www.openssh.com
  - Assignment
    - Install any other desktop environment or Linux distro and take screenshot

repository: StaymanHou/octopress

extension: markdown

repo_name: StaymanHou/octopress


text:
# Changelog for version 1.12.0

### New features & improvements

- PHP8 Support — Thanks [@ChristianVermeulen](https://github.com/ChristianVermeulen)

repository: akumarraheja/kstych-ubl-invoice

repo_name: akumarraheja/kstych-ubl-invoice


text:
---
title: "Doctrine 2 at ConFoo 2010"
authorName: jwage
authorEmail:
categories: []
permalink: /2010/03/15/doctrine-2-at-confoo-2010.html
---
This past week I was lucky enough to get to travel to Montreal for the
annual ConFoo conference, previously known as PHP Quebec. I presented on
the latest and greatest version of Doctrine, 2.0 for the PHP Trac. You
can find the slides on SlideShare.com
[here](https://www.slideshare.net/jwage/doctrine-2-enterprise-persistence-layer-for-php-3402070)
or view the presentation embedded below:

Doctrine 2 - Enterprise Persistence Layer For PHP

<object width="425" height="355">

</object>

View more presentations from Jonathan Wage.

repository: doctrine/doctrine-website

repo_name: doctrine/doctrine-website


text:
# Changelog
All notable changes to this project will be documented in this file.

## [1.4.0] - 2021-06-30
### Added

### Changed
* #54 Cached sources and classpath so that they are only retrieved once, and shared between validation and use

### Fixed

* #54 Method parameter type name standardisation

## [1.3.9] - 2021-06-30
### Added

### Changed

* #53 Standardising name of parameter types for methods, between when a MethodMatcher is constructed and evaluated

### Fixed

## [1.3.8] - 2021-06-29
### Added

### Changed

* #51 Extra null safety when checking method names, and static on-demand imports are checked when finding declaring methods

### Fixed

* #49 Allow multiple files in --cp

## [1.3.7] - 2021-06-23
### Added

### Changed

* Tweak to static method type resolution attempting to find single applicable type name from imports, if possible, before falling back to resolving

### Fixed

## [1.3.6] - 2021-06-16
### Added

### Changed

### Fixed
* Fixes for static imports, particularly better detection of when imports are really unused.
* MethodMatcher now works better when matching parameters that are arrays and type variables.

## [1.3.3] - 2021-06-09
### Added

### Changed

### Fixed
* Fixed case where adding a static import would remove an existing static import of the same name, even if this was valid.

## [1.3.1] - 2021-06-04
### Added

* Added a new ASTOperation the JavaPatternASTOperation, [read more in the wiki](https://github.com/alfasoftware/astra/wiki/Java-Pattern-Refactor).

### Changed

* ClassVisitor visits additional ASTNodes

### Fixed

## [1.2.1] - 2021-05-19
### Added

### Changed

* Type matcher now matches on parameterized supertypes
* Method matcher now allows custom predicates to be used for matching any AST node types handled by MethodMatcher

### Fixed

* Fix unused imports refactor so it doesn't lose inner types.
* Log the total number of files after filtering with the predicate

## [1.0.0] - 2021-03-06
### Added

* Initial commit! Please see our [README](https://github.com/alfasoftware/astra/blob/main/README.md) and [Wiki](https://github.com/alfasoftware/astra/wiki) for details on how to get started.

### Changed

### Fixed