ES6. Using yield
and yield*
.
function* a() {
var i = yield "first thing from a";
var j = yield "second thing from a";
return [i, j];
}
function* b() {
import copy | |
from abc import ABC, abstractmethod | |
from contextlib import contextmanager, nullcontext | |
from typing import ( | |
TYPE_CHECKING, | |
Any, | |
Callable, | |
ContextManager, | |
Generic, | |
Iterator, |
pub fn goofy(ctx: Context<Goofy>) -> ProgramResult { | |
// Manually pay the fresh account some money | |
**ctx | |
.accounts | |
.payer // some account owned by us, with some money | |
.to_account_info() | |
.try_borrow_mut_lamports()? -= 2000000; // random big-enough amount | |
**ctx.accounts.new_account.try_borrow_mut_lamports()? += 2000000; | |
// Allocate the new_account some space (it has money now). |
ES6. Using yield
and yield*
.
function* a() {
var i = yield "first thing from a";
var j = yield "second thing from a";
return [i, j];
}
function* b() {
Monads are composed of three ingredients. | |
First, for a given monad m, there are monadic values of type m a, for some type | |
variable a. In Haskell, if a variable x has type t, we write x :: t. | |
Here's a picture of a monadic value of type m a. | |
+--------\ | |
| | \ | |
| m | a > :: m a |
import RxSwift | |
import RxSwiftExt | |
class Signal<E>: ObservableConvertibleType { | |
private let _out: Variable<E> | |
var value: E { return _out.value } | |
init(out: Variable<E>) { | |
_out = out | |
} | |
func map<R>(selector: E -> R) -> Signal<R> { |
require 'minitest/autorun' | |
module Memoization | |
def memoize(f, injected_cache={}) | |
m = instance_method(f) | |
define_method(f) do |*args| | |
cache = injected_cache.clone | |
define_singleton_method(f) do |*args| | |
unless cache[args] | |
puts "Actually calculating..." |
#[proc_macro] | |
pub fn pubkey(input: proc_macro::TokenStream) -> proc_macro::TokenStream { | |
let s = parse_macro_input!(input as LitStr); | |
let pk: Pubkey = s.value().parse().unwrap(); | |
let bytes = pk.to_bytes().map(|b| LitByte::new(b, Span::call_site())); | |
let output = quote! { | |
anchor_lang::solana_program::pubkey::Pubkey::new_from_array([#(#bytes,)*]) | |
}; | |
output.into() | |
} |
module Mappers | |
data Identity a = MkIdentity a | |
Functor Identity where | |
map f (MkIdentity x) = MkIdentity (f x) | |
repapply : Nat -> (a -> a) -> (a -> a) | |
repapply Z f = id | |
repapply (S k) f = f . repapply k f |
I want to write about why GDB is a great tool for learning C. At least part of the difficulty in learning C is that the language isn’t as interactive as using Python or Ruby.
TL;DR You can kinda use gdb as a repl for c
What’s the smallest possible program we could debug to learn about pointers?
function NumberPicker({ onResult }: { onResult: (x: number) => void }) { | |
const inputEl: any = useRef(null) | |
return ( | |
<React.Fragment> | |
<label> | |
Enter a number: <input type="number" ref={inputEl} /> | |
</label> | |
<button onClick={() => onResult(Number(inputEl.current.value))}> | |
Ok | |
</button> |