Skip to content

Instantly share code, notes, and snippets.

View Iainmon's full-sized avatar
🥶

Iain Moncrief Iainmon

🥶
View GitHub Profile
@Iainmon
Iainmon / nanos_micros_millis.cpp
Last active July 9, 2019 05:39
Easy way to get time in c++.
#include <chrono>
uint64_t millis()
{
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}
uint64_t micros()
{
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();;
using namespace physics;
class Drawable {
public:
Vector2D position;
Vector2D velocity;
Drawable() {
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
class Mamal {
public:
virtual void move() = 0;
@Iainmon
Iainmon / Struct_vs_Class.cr
Created August 9, 2019 03:19
An example of how classes are pointers, and structs are by value in Crystal Lang.
class Person
property name : String
def initialize(@name : String); end
end
struct Human
property name : String
def initialize(@name : String); end
@Iainmon
Iainmon / Project_Tree_Formatting_Issue.php
Last active August 9, 2019 04:20
I was trying to debug something
<?php
class Project {
public $id;
public static $lastId = 1;
public $projects = [];
void ClampBodyToScreenArea(float *axis, const float maxAxisDistanceFromCenter, const float velocity, const float screenAxisLength) {
if (velocity > 0) {
*axis = maxAxisDistanceFromCenter + 1;
} else {
*axis = screenAxisLength - maxAxisDistanceFromCenter - 1;
}
}
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
struct Entry {
int id;
string category;
macro for(definition, condition, incrimentation, &block)
{{definition}}
while {{condition}}
{{block.body}}
{{incrimentation}}
end
end
macro for(expr)
({{expr.args.first.args.first}}).each do |{{expr.name.id}}|
/// <reference path="../node_modules/assemblyscript/index.d.ts" />
declare type u64 = number;
// It’s time for constant time complexity!
var memory = new Map<u64, u64>();
// Fibonacci wrapper for memory
export function fib(n: u64): u64 {
/// <reference path="../node_modules/assemblyscript/index.d.ts" />
declare type u64 = number;
// Recursive Fibonacci function
export function fib(n: u64): u64 {
if (n <= 1) {
return n;