Skip to content

Instantly share code, notes, and snippets.

View arilotter's full-sized avatar

Ari Lotter arilotter

View GitHub Profile
@arilotter
arilotter / playground.rs
Created October 10, 2019 21:12 — forked from rust-play/playground.rs
Code shared from the Rust Playground
struct C120;
enum Zone {
Graveyard
}
struct MoveToZone {
to: Zone,
from: Zone
}
@arilotter
arilotter / 00_warning.md
Created September 26, 2016 21:09 — forked from joepie91/00_warning.md
Asynchronous fs.exists

Important warning

You should almost never actually use this. The same applies to fs.stat.

Checking whether a file exists before doing something with it, can lead to race conditions in your application. Race conditions are extremely hard to debug and, depending on where they occur, they can lead to data loss or security holes. Using the synchronous versions will not fix this.

Generally, just do what you want to do, and handle the error if it doesn't work. This is much safer.

  • If you want to check whether a file exists, before reading it: just try to open the file, and handle the ENOENT error when it doesn't exist.
  • If you want to make sure a file doesn't exist, before writing to it: open the file using an exclusive mode, eg. wx or ax, and handle the error when the file already exists.
@arilotter
arilotter / robot.js
Created December 4, 2012 19:40 — forked from Sairento-92/robot.js
Boberczus
function Robot(robot) {}
Robot.prototype.onIdle = function(ev) {
var robot;
robot = ev.robot;
robot.ahead(130);
robot.rotateCannon(50);
robot.back(130);
robot.rotateCannon(50);
if(robot.life==100)
robot.clone()
import time
import win32api, win32con
def press(x):
win32api.keybd_event(VK_CODE[x], 0,0,0)
win32api.keybd_event(VK_CODE[x],0 ,win32con.KEYEVENTF_KEYUP ,0)
def play():
time.sleep(1)
s = time.time()