Skip to content

Instantly share code, notes, and snippets.

View i-hardy's full-sized avatar
🏳️‍🌈
the lambda calculus belongs to lesbians

Imogen Hardy i-hardy

🏳️‍🌈
the lambda calculus belongs to lesbians
  • Brighton, UK
View GitHub Profile
@i-hardy
i-hardy / temperature.rock
Created November 6, 2022 15:40
Celsius and farenheit conversion. In Rockstar.
(Celsius -> Farenheit)
Love takes everything
Billie Jean was exquisite
Annie was broke
Tonight is all in
Put Billie Jean over Annie into the storm
Put everything of the storm into my heart
Give back tonight with my heart
@i-hardy
i-hardy / uuids.rs
Last active April 24, 2020 08:30
Generating UUIDs in Rust
extern crate hex;
extern crate rand;
use rand::Rng;
fn create_byte_vector() -> Vec<u8> {
let mut random_bytes = rand::thread_rng().gen::<[u8; 16]>();
random_bytes[6] = (random_bytes[6] & 0x0f) | 0x40;
random_bytes[8] = (random_bytes[8] & 0x3f) | 0x80;
random_bytes.to_vec()
@i-hardy
i-hardy / github-stream.js
Last active March 12, 2019 16:40
Streaming data from the GitHub GraphQL API with an async generator
function githubStream(delayTime = 2) {
const delay = () => new Promise(resolve => setTimeout(resolve, delayTime * 1000))
let repos = [];
let maxIterations = 100;
function getCursor() {
if (repos.length) {
return repos[repos.length - 1].cursor;
}
return '';
@i-hardy
i-hardy / asyncy-awaiter.js
Last active March 7, 2019 16:41
DIY async-await with generators and promises
const request = asyncy('https://jsonplaceholder.typicode.com/todos')
awaiter()
.then(awaiter)
.then(console.log)
function awaiter(item) {
return request.next(item).value
}
@i-hardy
i-hardy / actions.js
Last active July 29, 2020 12:06
Streamlining Vuex actions with async/await and higher-order functions
import axios from 'axios';
export const fetchSomeData = async (store, params) => {
try {
const res = await axios.get(`endpoint/${params.id}`);
return store.commit('SET_SOME_DATA', res.data.result);
} catch (error) {
console.error(error.message);
}
};
@i-hardy
i-hardy / actions.js
Last active January 11, 2018 11:02
Unit-testing Axios CancelToken behaviour
const tableCanceller = new Cancellation();
...
export const fetchTableData = (store, payload) => {
tableCanceller.check('Table API request cancelled');
return axios
.post(`${payload.profileId}/report/${payload.reportId}/tabular`, payload.body, {
params: {
fromDate: payload.body.fromDate,
toDate: payload.body.toDate,