Skip to content

Instantly share code, notes, and snippets.

View ianks's full-sized avatar
🧪
new gem alert: nicetest (minitest CLI / config)

Ian Ker-Seymer ianks

🧪
new gem alert: nicetest (minitest CLI / config)
View GitHub Profile
@ianks
ianks / build-libclanga.sh
Created February 23, 2024 22:08
Build bindgen with libclang
#!/bin/bash
git clone --depth 1 --branch release/14.x https://github.com/llvm/llvm-project
cd llvm-project
mkdir build
cd build
echo "Configuring clang"
cmake -G "Ninja" -DENABLE_SHARED=OFF -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release ../llvm
@ianks
ianks / wrapped_struct.rs
Last active December 4, 2022 23:45
Wrapped struct for magnus
use magnus::{error::Error, exception, gc, value::Value, RTypedData, TryConvert, TypedData};
use std::{marker::PhantomData, ops::Deref};
/// A small wrapper for `RTypedData` that keeps track of the concrete struct
/// type, and the underlying [`Value`] for GC purposes.
#[derive(Debug)]
#[repr(transparent)]
pub struct WrappedStruct<T: TypedData> {
inner: RTypedData,
phantom: PhantomData<T>,
@ianks
ianks / wrapper_sorbet.rb
Created March 17, 2022 01:35
Sorbet wrapper method?
# How would I write a sig such that #wrapped_start the same type signature
# as the subclass' #start method (i.e. Car#start or Boat#start)
class Vehicle
def wrapped_start
start
end
end
class Car < Vehicle
sig { params(key: String, license: License).returns(T::Boolean) }
@ianks
ianks / nginx.conf
Created December 7, 2021 13:48
WPEngine Reverse Proxy Nginx Config
user nginx;
worker_processes 10;
worker_rlimit_nofile 16384;
pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log warn;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
{
"id": 820982911946154500,
"email": "[email protected]",
"closed_at": null,
"created_at": "2019-07-30T12:29:54-04:00",
"updated_at": "2019-07-30T12:29:54-04:00",
"number": 234,
"note": null,
"token": "123456abcd",
"gateway": null,
@ianks
ianks / yield_it.rb
Created May 24, 2021 04:37
yield it back
class BlogPostCreator
def create_post
if similar_post_already_created?
yield_to_user("This looks like a duplicate, sure you want to post this?") || halt
end
# do the things...
end
end
export const UserAvatar = () => {
const [isHidden, setHidden] = React.useState(false);
// Will instantly hide the component, causing a jarring UX
if (isHidden) {
return null;
}
return (
<>
def sum_price(items: Enumerable<RespondTo[price: Integer]>
# ...
end
export class UserList extends React.Component {
handleClick = (item) => console.log('You clicked ', this.props.group);
render() {
return (
<HugeListOfItems
group={group}
handleClick={this.handleClick}
/>
);
// Overly complicated search form which uses custom state management 👎
function SearchBox() {
const [queryParams, setQueryParams] = useState({ showAllResults: false });
const handleSearchChange = (ev) => {
const eventValue = ev.target.value;
setQueryParams({ ...queryParams, q: eventValue });
}