Skip to content

Instantly share code, notes, and snippets.

View rtpg's full-sized avatar
:shipit:
Investigating some magic

Raphael Gaschignard rtpg

:shipit:
Investigating some magic
View GitHub Profile
@rtpg
rtpg / work.sh
Created August 28, 2012 12:46
Run this when trying to get something done
#! /bin/bash
# Push a message on-screen every 60 seconds to remind you of what you're supposed to be doing
# requires lib-notify (most distros have it I think)
while [ 1 ]; do
notify-send Hey "Get back to work"
sleep 60;
done
/*
* photon.cpp
* photonSplit
*
* Created by Diane Nguyen on 4/25/13.
* Copyright 2013 __MyCompanyName__. All rights reserved.
*
*/
#include "photon.h"
#include <cstdlib>
@rtpg
rtpg / pymongo.py
Created April 17, 2016 13:52
pymongo Cheatsheet
db = MongoClient('localhost', 27017).some_db # some_db is the DB name
db.table_name.insert_one({ # table name
'key1': value1,
'key2': value2
})
db.table_name.update_many({'key1':'some_value'}, # update all elts with key1 == 'some_value', setting key2 to 'processed'
{'$set': {'key2': 'processed'})
@rtpg
rtpg / Models.js
Last active June 23, 2016 14:55
Example of useful effects
"use strict"
// module App.Models
exports.createUser = function(u){
// you might want to put some real implementations here
return 3;
};
exports.lookupUser = function(u){
@rtpg
rtpg / e-Book Generation.ipynb
Last active September 17, 2016 10:40
My EPUB generation script
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rtpg
rtpg / Carmack Plan File Generator.ipynb
Created September 26, 2016 01:00
Carmack Plan File Generator
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import Data.Exists (Exists, mkExists, runExists)
type Circle = {x:: Int, y:: Int, r:: Int}
type Rectangle = {x:: Int, y:: Int, w:: Int, h:: Int}
drawCircle :: Circle -> String
drawCircle c = "This is a circle!"
drawRectangle :: Rectangle -> String
drawRectangle r = "This is a rectangle!"
@rtpg
rtpg / DrawComponents.purs
Created October 1, 2016 06:43
Draw Components (Purescript)
import Data.Exists (Exists, mkExists, runExists)
type Circle = {x:: Int, y:: Int, r:: Int}
type Rectangle = {x:: Int, y:: Int, w:: Int, h:: Int}
drawCircle :: Circle -> String
drawCircle c = "This is a circle!"
drawRectangle :: Rectangle -> String
drawRectangle r = "This is a rectangle!"

Keybase proof

I hereby claim:

  • I am rtpg on github.
  • I am rtpg (https://keybase.io/rtpg) on keybase.
  • I have a public key ASD-wP2usgoqaEFBlO3ZpUS96VO7chqGCyzeRsU2gEWsego

To claim this, I am signing this object:

@rtpg
rtpg / sameShape.ts
Last active March 9, 2019 01:56
How to write an assertion that two objects are the same shape in Typescript
// this worked in Typescript 3.2.4
// It feels like we should be able to say SameShape<Q extends R, R extends Q>, but this triggers circular reference
// detection in Typescript. Somehow going to {[K in keyof Q]: Q[K]} solves this (though maybe this won't catch things
// like symbols?)
type SameShape<Q extends R, R extends { [K in keyof Q]: Q[K] }> = {
[K in keyof Q]: R[K] // re-asserting every key of Q is present in R with the same type
} & { // anding the types together will catch any conflicts
[K in keyof R]: Q[K] // re-asserting every key of R is present in Q with the same type
}