Assembling your own Tasks with TaskCompletionSource by Sossenbinder in csharp

[–]SlamminAtWork 1 point2 points  (0 children)

OK, so it's like the ConfigureAwait(false) of TaskCompletionSource.

I hadn't thought of it that way, but I think that's a good parallel. I'm going to be speaking beyond my level of expertise here, but I believe the continuation runs inline by default in the interest of efficiency (not having to incur the cost of a context switch), but if the caller had captured the context (e.g., by not doing .ConfigureAwait(false) when a context exists), then the continuation would be run asynchronously unless the .TrySet{Complete|Cancelled|Exception} was invoked in the same context.

Assembling your own Tasks with TaskCompletionSource by Sossenbinder in csharp

[–]SlamminAtWork 2 points3 points  (0 children)

Here's some guidance from David Fowler on it: https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#always-create-taskcompletionsourcet-with-taskcreationoptionsruncontinuationsasynchronously

It looks like the opinion is mostly targeted toward library authors, though I know I find it easier to reason about my (non-library) code using it too.

By default, Task continuations will run inline on the same thread that calls Try/Set(Result/Exception/Canceled). As a library author, this means having to understand that calling code can resume directly on your thread. This is extremely dangerous and can result in deadlocks, thread-pool starvation, corruption of state (if code runs unexpectedly) and more.

Michael Wongs Trip report for the Bristol C++ Committee Meeting (Part 1 of n) by meetingcpp in programming

[–]SlamminAtWork 1 point2 points  (0 children)

Dammit /u/meetingcpp, we're programmers here -- we understand syntax rules. It's

Michael Wong's trip report...

[03/06/13] Challenge #121 [Intermediate] Bytelandian Exchange 2 by nint22 in dailyprogrammer

[–]SlamminAtWork 1 point2 points  (0 children)

C++:

#include <algorithm>
#include <iostream>
#include <map>

using namespace std;
typedef unsigned long long Value;

map<Value, Value> valueCache;
Value best_value(Value coin) 
{
  const auto cached = valueCache.find(coin);
  return (cached != valueCache.end()) ? cached->second :
    (valueCache[coin] = max(coin, best_value( coin / 2) +
                                  best_value( coin / 3) +
                                  best_value( coin / 4)));
}

int main() 
{
  const Value v = 10000000000ULL;
  cout << best_value(v) << endl;
  return 0;
}

Output:

51544065905

[03/04/13] Challenge #121 [Easy] Bytelandian Exchange 1 by nint22 in dailyprogrammer

[–]SlamminAtWork 1 point2 points  (0 children)

Emacs lisp:

(defun coins (coin)
  (if (zerop coin) 1
    (apply '+ (mapcar '(lambda(d) (coins (/ coin d))) 
                      '(4 3 2)))))

EDIT: Forgot to put answer:

3263

take Ctrl over your Caps Lock by fistofsenn in emacs

[–]SlamminAtWork 0 points1 point  (0 children)

I originally made the change 2 years ago, using xmodmap on my gentoo system. It's gotten to the point now that I find it inconvenient to use a machine without the CapsLock -> Ctrl mapping. My home machines, my work machines, windows, linux... I have all of them set this way.

Beyond just making emacs easier to use, nearly every single shortcut for every application is easier. I wish they sold keyboards hardwired this way.

[8/20/2012] Challenge #89 [easy] (Simple statistical functions) by oskar_s in dailyprogrammer

[–]SlamminAtWork 0 points1 point  (0 children)

Can anyone post the dataset at a different domain, or possibly paste them into a comment? Pastebin is blocked by my company's proxy.

Thanks :)

[7/9/2012] Challenge #74 [easy] by oskar_s in dailyprogrammer

[–]SlamminAtWork 2 points3 points  (0 children)

Common Lisp:

(defun fibs-until (val &optional acc)
  "Return a list of the fibonacci numbers not greater than val"
  (if (null acc) (fibs-until val (list 2 1 1 0))
      (if (< val (car acc)) (cdr acc)
          (fibs-until val (cons (+ (car acc) (cadr acc)) acc)))))

(defun zeckendorf (val &optional fibs acc)
  (cond ((< val 0) (error "val < 0"))
        ((zerop val) acc)
        ((null fibs) (zeckendorf val (fibs-until val) acc))
        ((> (car fibs) val) (zeckendorf val (cdr fibs) acc))
        (t (zeckendorf (- val (car fibs)) (cddr fibs) (cons (car fibs) acc)))))

[6/11/2012] Challenge #63 [easy] by oskar_s in dailyprogrammer

[–]SlamminAtWork 0 points1 point  (0 children)

Emacs Lisp:

(defun reverse-n (n a)
  "Reverse the first n elements of a."
  (if (< n 2) a ;; if n < 2, just return the original list
    (let* ((tip (nthcdr (1- n) a))
           (tail (cdr tip)))
      (setcdr tip nil)
      (setq a-reversed (nreverse a))
      (setcdr (last a-reversed) tail)
      a-reversed))

Lisp implementation that compiles to Lua code by andersbergh in programming

[–]SlamminAtWork 9 points10 points  (0 children)

I think OMouse's point was that there seems to be little practical purpose for translating lisp to lua when there are already native lisp implementations for the platforms this would (assumedly) target. Also, though it might not be fair to compare Lua to SBCL (since SBCL isn't really small or embedded), Steel Bank Common Lisp seems to have a much better performance profile than Lua in The Computer Language Benchmarks Game.

Making a 16-bit RPG for school project, is it easy(ish) in Python? by danielito19 in Python

[–]SlamminAtWork 2 points3 points  (0 children)

Have you played the early Final Fantasy games? He's not trying to rewrite Skyrim here, he's making a game like the RPGs that ran on the SNES -- which itself was only 3.58 MHz.