Skip to content

Instantly share code, notes, and snippets.

View punmechanic's full-sized avatar

Dan punmechanic

  • Staff Security Engineer @ Riot Games
  • California, United States
  • 02:56 (UTC -07:00)
  • Mastodon @[email protected]
View GitHub Profile
a.out: file format elf64-x86-64
Contents of section .interp:
02a8 2f6c6962 36342f6c 642d6c69 6e75782d /lib64/ld-linux-
02b8 7838362d 36342e73 6f2e3200 x86-64.so.2.
Contents of section .note.ABI-tag:
02c4 04000000 10000000 01000000 474e5500 ............GNU.
02d4 00000000 03000000 02000000 00000000 ................
Contents of section .note.gnu.build-id:
02e4 04000000 14000000 03000000 474e5500 ............GNU.
type Action =
| { type: 'ReturnsPromise' }
| { type: 'ReturnsUndefined' }
type R<A> =
| A extends { type: 'ReturnsPromise' } ? Promise<unknown> : never
| A extends { type: 'ReturnsUndefined' } ? undefined : never
| unknown
type Dispatch<A> = (action: A) => R<A>
// Is there any way I can avoid allocating new memory here? `bindings` lives for the lifetime of the application, so it's not going out of scope.
void register_type(lua_State* L, const char* type_name, const binding bindings[], int num_bindings) {
for (int i = 0; i < num_bindings; i++) {
binding b = bindings[i];
// This will go out of scope at the end of this function and is essentially akin to passing a null reference. It looks like this is because I am passing a reference to the local variable b rather than a reference to the array member bindings[i].
lua_pushlightuserdata(L, &b);
// Now, if I malloc this binding (which is shit), this will work just fine, because the memory will be allocated on the heap and stay live until after this function exits.
binding* shit_binding = malloc(sizeof(binding));
@punmechanic
punmechanic / EffectualAPI.ts
Created May 15, 2019 13:05
awful effect-based HTTP. one benefit this provides is that it is more exhaustive than using a functional approach because it uses different 'Response' types. But it is quite verbose and would need more work to be a serious solution.
// TODO: This does not work in mock mode.
import { HTTPAPI, NotFoundError } from "../api"
import React from "react"
type Maybe<T> = T | undefined
export interface Request<T> {
then<T2>(f: (data: Maybe<T>) => Maybe<T2>): Request<Maybe<T2>>
run(): Promise<Response<Maybe<T>>>
}
class App extends Component {
constructor(props) {
super(props)
this.state = {
// We initialise this here since we need a sensible default
viewModel: new SchedulerData("2018-12-18", ViewTypes.Week)
// the resources key is removed because it is never accessed directly.
// test key is also removed because it's useless
}
@punmechanic
punmechanic / makeContainerComponent.ts
Last active October 27, 2018 02:40
Creates generic container components for fetching asynchronous data
import * as React from "react"
interface ChildProps<T, E = any> {
data: T | undefined
error: E | undefined
isFetching: boolean
}
type State<T, E> = ChildProps<T, E>
import { Switch, Route, withRouter } from "react-router"
import { BrowserRouter, Link } from "react-router-dom"
import invariant from "invariant"
import { Map } from "immutable"
const AsyncCapableRouteContext = React.createContext({
registerRoute() {},
unregisterRoute() {}
})
{-
Upserts into the given list, based on the given predicate.
If the given predicate matches any element in the list, then the first element
that matches that predicate in the list has the given function applied to it. A
new list is then returned with the new element present.
If the given predicate does not match any elements in the list, then the given
default element is inserted.
struct size_t {
};
int do_read_from_somewhere(size_t* output) {
size_t out;
*output = out;
return 0;
}