Skip to content

Instantly share code, notes, and snippets.

View jorendorff's full-sized avatar

Jason Orendorff jorendorff

View GitHub Profile

This was written in response to: https://twitter.com/hillelogram/status/1227118562373963776


People mix the predicate "If a directed graph is a tree, it's a DAG" with the proposition "For all directed graphs, if a directed graph is a tree, it's a DAG".

First, for simplification: let's assume we're talking here about all graphs in the world with up to 10 nodes to be able to enumerate them. Also, note that we're talking about directed, not undirected, graphs.

To prove the proposition "For all..." is true, which is "(For graph G1, if it's a tree, it's a DAG) AND (For graph G2, if it's a tree, it's a DAG) AND...", since it's ANDs, we need to prove (For graph G1, if...) is true and we need to prove (For graph G2, if...) is true, ... etc.

@jorendorff
jorendorff / playground.rs
Created October 11, 2017 19:19 — forked from anonymous/playground.rs
Rust code shared from the playground
use std::fmt::Debug;
struct Reader<'a> {
buf: &'a [u8],
}
impl<'a> Reader<'a> {
fn read<'b>(&'b mut self, len: usize) -> Result<&'a [u8], ()> {
if len <= self.buf.len() {
let (read, remains) = self.buf.split_at(len);
@jorendorff
jorendorff / heads.py
Created August 4, 2017 04:21 — forked from jimblandy/heads.py
There must be a better way to compute this...
import random
random.seed()
def flip():
return random.choice([True, False])
def run():
b = flip()
n = 1
@jorendorff
jorendorff / editor.rs
Last active July 20, 2017 17:59 — forked from levicole/editor.rs
extern crate termion;
use std::io::{Write, Stdout, stdout, stdin};
use termion::event::{Key, Event};
use termion::input::TermRead;
use termion::raw::{IntoRawMode, RawTerminal};
use termion::screen::AlternateScreen;
pub struct Editor {
screen: AlternateScreen<Stdout>,
# Some more privileged methods, with some private data.
class Availability:
def __init__(self):
self._is_open = False
def open(self):
self._is_open = True
def close(self):
self._is_open = False
@jorendorff
jorendorff / 7.md
Last active February 20, 2017 13:54 — forked from anonymous/7.md

CIS claims 72 terrorists have come to the US from the 7 countries in Trump's travel ban. Here's what I learned.

  • These cases aren't about actual attacks in the U.S. The Ninth Circuit said "The Government has pointed to no evidence that any alien from any of the countries named in the Order has perpetrated a terrorist attack in the United States." The reason I got into this mess is people claiming the court lied. They did not lie. Nor is CIS lying. This list is mainly people who aided terrorist groups, and a few FBI sting operations. In all 11 cases I got to, no attack occurred.

  • These people were not all admitted to the U.S. under current vetting procedures. See the last case listed below.

Cases

I had an hour to spend. I looked into these cases, mostly relying on news accounts.

# To run this code, you'll need the sample data (133 MB download, unzips to 492 MB):
# http://bit.ly/2avfASU
# tar xjf sample.tar.bz2
defmodule Elindex.Searcher do
def search(word) do
File.ls!("sample")
|> Stream.map(fn(filename) ->
fn ->
Path.join("sample", filename)
@jorendorff
jorendorff / gist:5156063
Last active December 14, 2015 22:09 — forked from fflorent/gist:5155923
function evaluate(context, expr, origExpr, onSuccess, onError)
{
var result;
var commandLine = createFirebugCommandLine(context, win);
// gets the debuggee object:
var dglobal = DebuggerLib.getDebuggeeGlobal(context.window, context);
var resObj;
// that works:
commandLine.someFunction = dglobal.makeDebuggeeValue(function()

Good-bye constructor functions?

tl;dr

Constructor function were workaround to specify constructor for a class without class. Now, having class nothing presribes the class being equivalent to its constructor. It always brought confusion and now with constructor empowered, it brings two-space problem. The class keyword can return plain objects, which have [[Construct]] calling the constructor of the class.

Problems

@jorendorff
jorendorff / post.rb
Created December 19, 2012 00:58 — forked from sam452/post.rb
require 'video_title_validator'
class Post < ActiveRecord::Base
attr_accessible :body, :title, :image, :video_title, :video_url
validates :video_url, :presence => true, :if => :video_title_present?
def video_title_present?
puts "YES IT IS BEING CALLED, FINALLY"
!self.video_title.blank?