This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait FileState {} | |
// We need this to define | |
// `close` method for multiple states | |
trait Closable { | |
fn close(self) -> File<ClosedFile>; | |
} | |
struct File<S: FileState> { | |
state: S, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rust | |
on: | |
pull_request: | |
branches: [ "master" ] | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createReadStream } = require('fs'); | |
const { promisify } = require('util'); | |
const stream = require('stream'); | |
const { GraphQLUpload } = require('graphql-upload'); | |
// Create a promisified version of the `pipeline` function | |
const pipeline = promisify(stream.pipeline); | |
const resolvers = { | |
Mutation: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag'; | |
import { MapperKind, mapSchema, getDirectives } from '@graphql-tools/utils'; | |
const typeDef = gql` | |
directive @ownerType(t: String! ) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION | |
`; | |
const directiveName = typeDef.definitions[0].name.value; | |
const transformer = (schema) => { | |
return mapSchema(schema, { | |
[MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName, parentTypeName) => { | |
const directive = getDirectives(schema, fieldConfig).find( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pg_dump -Ft dbname > backup.tar | |
pg_restore -Ft backup.tar | psql dbname | |
# or this for much better compression | |
pg_dump -Ft dbname | gzip > backup.tar.gz | |
gunzip -c backup.tar.gz | pg_restore -Ft -d dbname | |
# with custom host and username | |
pg_dump -h localhost -p 5433 -U postgres -Ft dbname ..... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::mem::size_of; | |
static B: [u8; 10] = [99, 97, 114, 114, 121, 116, 111, 119, 101, 108]; | |
static C: [u8; 11] = [116, 104, 97, 110, 107, 115, 102, 105, 115, 104, 0]; | |
fn main() { | |
let a: usize = 42; | |
let b: &[u8; 10] = &B; | |
let c: Box<[u8]> = Box::new(C); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let a: f32 = 42.42; | |
let b: f32 = -42.42; | |
let a_bits: u32 = a.to_bits(); | |
let b_bits: u32 = b.to_bits(); | |
let a_sign: u32 = a_bits >> 31; | |
let b_sign: u32 = b_bits >> 31; | |
println!("a_sign: {}", a_sign); // a_sign: 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::mem::transmute; | |
fn main() { | |
let big_endian: [u8; 4] = [0xAA, 0xBB, 0xCC, 0xDD]; | |
let little_endian: [u8; 4] = [0xDD, 0xCC, 0xBB, 0xAA]; | |
let a: i32 = unsafe { transmute(big_endian) }; | |
let b: i32 = unsafe { transmute(little_endian) }; | |
println!("{} vs {}", a, b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let a: f32 = 42.42; | |
let frankentype: u32 = unsafe { | |
println!("{}", a); | |
std::mem::transmute(a) | |
}; | |
println!("{}", frankentype); | |
println!("{:032b}", frankentype); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use thiserror::Error | |
#[derive(Debug, Error)] | |
#[non_exhaustive] | |
pub enum PuzzleError { | |
#[error("Piece {0} doesn't fit!")] | |
WontFit(u16), | |
#[error("Missing a piece")] | |
MissingPiece, | |
} |