Skip to content

Instantly share code, notes, and snippets.

View piboistudios's full-sized avatar
💭
Writing some Haxe FFIs

Gabriel Hayes piboistudios

💭
Writing some Haxe FFIs
  • St. Louis, Missouri
View GitHub Profile
@piboistudios
piboistudios / cell-types-example.rs
Created July 16, 2018 15:49 — forked from rust-play/playground.rs
Code shared from the Rust Playground
// Practice with Cell Smart Pointers
// Cells grant interior mutability:
// Cells allow you to mutate the interior value, these can only be used with
// values on the stack or Copy values
// RefCells allow you mutate the interior reference use this for values on the heap
// or Clone values
@piboistudios
piboistudios / simple-aabb.rs
Last active July 12, 2018 20:54 — forked from rust-play/playground.rs
Code shared from the Rust Playground
// Simple Axis-Aligned Bounding Box
// Author: Gabriel Hayes
#[derive(Debug)]
struct AABB {
x: i64,
y: i64,
wx: i64,
hy: i64,
}
@piboistudios
piboistudios / threads-and-channels.rs
Last active July 12, 2018 19:07 — forked from rust-play/playground.rs
[RUST]Concurrency 1.1 (#4)
use std::thread;
use std::time::Duration;
fn main() {
concurrency_demo_1();
concurrency_demo_2();
}
// this simply demonstrates how to move data from an outer scope into a thread's scope:
fn concurrency_demo_1() {
let v = vec![1, 2, 3];
@piboistudios
piboistudios / complex-channel.rs
Last active July 12, 2018 19:08 — forked from rust-play/playground.rs
[RUST]Channels (#5)
use std::thread;
use std::sync::mpsc;
use std::time::Duration;
fn main() {
// start by creating a channel
let (tx, rx) = mpsc::channel();
// we need to create a clone of the transmitter because each thread actually
// owns the copy we give it... and it's greedy so it won't give it back :(
@piboistudios
piboistudios / cons-list.rs
Last active July 12, 2018 19:06 — forked from rust-play/playground.rs
[RUST]Cons List (#1)
// We need a reference counting pointer to have multiple references to a single object
use std::rc::Rc;
// We need a RefCell to be able to internally mutate an immutable value
use std::cell::RefCell;
#[derive(Debug)]
// definition of a linked list
enum List {
// We may have multiple references to a given list object, therefore we need Rc<T>
@piboistudios
piboistudios / parent-children-tree.rs
Last active December 31, 2023 14:15 — forked from rust-play/playground.rs
[RUST]Parent-Children Tree (#2)
// we will use weak references with the Rc<T> (reference counting pointer) type
// weak references allow us to make references to a value that will -not- keep it alive
// this is perfect in the intsance of children, as we will soon see
use std::rc::{Rc,Weak};
use std::cell::RefCell;
// this example builds upon the last by storing a vector of children as well as a parent
#[derive(Debug)]
struct Node {
@piboistudios
piboistudios / concurrency-getting-started.rs
Last active July 12, 2018 19:07 — forked from rust-play/playground.rs
[RUST]Concurrency 1.0 (#3)
use std::thread;
use std::time::Duration;
// this simple example spwans a thread and runs an operation while running the same operation on the main thread
fn main() {
// the thread::spawn function expects a Closure; Rust closure syntax is |params_list...| { expr body }
// if the exprsesion is one line curly braces can be omitted
// type annotations are optional in closures, as Rust implicitly infers the types the first time the Closure is called
let handle = thread::spawn(|| {
for i in 1..10 {
@piboistudios
piboistudios / gcloud-datastore-utils.js
Created May 30, 2018 18:55
Google Cloud Datastore Filtered Query Generator
const keyfile = require('my-keyfile.json');
let config = {
credentials: keyfile
};
const Datastore = require('@google-cloud/datastore')(config);
let genFilteredQuery = query => {
let _query = Datastore.createQuery(query.kind !== null ? query.kind : '');
@piboistudios
piboistudios / server.js
Last active May 2, 2018 04:31
Node.js Server Tailored to Static Webpages with a .html fallback assumption
// I basically made this so that I could divide logical sections of a website into different SPAs for speed without
// serving the entire website up front. This is heavily based on the below article, although I promise I didn't C/P:
// http://adrianmejia.com/blog/2016/08/24/Building-a-Node-js-static-file-server-files-over-HTTP-using-ES6/
const http = require('http');
const port = process.argv[2] || 9000;
http.createServer(function (request, result) {
// import the necessary packages
const url = require('url');
const fs = require('fs');