Skip to content

Instantly share code, notes, and snippets.

View justinvh's full-sized avatar
😀

Justin Bruce Van Horne justinvh

😀
  • SpaceX
  • New York, New York
  • 20:22 (UTC -04:00)
  • LinkedIn in/justinvh
View GitHub Profile
@justinvh
justinvh / gist:657118
Created October 31, 2010 20:44
A V8 Developer Talk in Global Objects and Templates
Session Start: Sun Oct 31 11:52:15 2010
Session Ident: #v8
15[11:52:15] * Now talking in #v8
03[11:52:15] * Topic is 'see #chromium, http://code.google.com/p/v8/'
03[11:52:15] * Set by mal on Tue Sep 02 12:03:02
[11:54:41] <mraleph> justinvh: hi! i don't see SetInternalFieldCount being called in your code. that's seems broken to me :-)
07[11:54:43] <justinvh> Allright. mraleph -- Always a pleasure to talk :)
[11:55:51] <mraleph> justinvh: same here :-)
07[11:56:30] <justinvh> Anyhow, I wasn't storing anything internally to that object. I can see the check that goes bad happens to be with that index, but it happens when I am instantiating the context...
07[11:56:52] <justinvh> Literally: ObjectTemplate::New() and then creating a context.
@justinvh
justinvh / v8-files.js
Created December 16, 2011 05:50
Taking advantage of function->string
function files(where, opts) {
/***
Generates a list of files from the output of `ls`.
Arguments:
where -- From where to list files (default '.')
opts -- Optional parameters that can be passed to `ls`.
***/
where = where || ".";
opts = opts || [];
@justinvh
justinvh / snowjob.py
Created December 28, 2011 01:37 — forked from sontek/snowjob.py
Make your terminal snow with python
#!/usr/bin/env python
import os
import random
import time
import platform
snowflakes = {}
try:
# Windows Support
@justinvh
justinvh / augmented_logging_context_manager_py3.py
Last active December 15, 2015 04:38
This gist demonstrates how to augment a logging record. In the example below we use it to change how a context manager logs. This is a Python 3+ solution, but can be converted to 2.7 fairly easily.
import logging
import inspect
import sys
import time
import contextlib
class AugmentedLogger(logging.getLoggerClass()):
"""A simple augmented logger that allows you to specify an arbitrary
stack-depth when logging relative to the caller function.
@justinvh
justinvh / output_iterator.cpp
Last active December 27, 2015 10:29
type-safety through obfuscation: enforcing an output iterator
#include <iterator>
#include <type_traits>
#include <iostream>
template <class Iter, class Tag>
using has_tag =
std::enable_if<
std::is_convertible<
typename std::iterator_traits<Iter>::iterator_category,
Tag>::value,
template <class OutputIter, class = void>
class Foo;
template <class OutputIter>
class Foo<OutputIter, is_output_iterator<OutputIter>> {
/* some class with an output iterator */
};
@justinvh
justinvh / suffix.cpp
Last active June 7, 2020 06:46
C++11 _format suffix literal for .format() like string arguments.
#include <string>
#include <vector>
#include <sstream>
#include <exception>
namespace std {
std::string to_string(const char* value)
{
return std::string(value);
}
@justinvh
justinvh / django.formset.js
Last active June 4, 2018 21:30
Easier formset factories with JavaScript
/**
* Copyright 2013 Justin Bruce Van Horne <justinvh@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@justinvh
justinvh / bf-llvm.cc
Created January 11, 2014 03:15
toy bf-llvm program
#include <vector>
#include <cstdint>
#include <iostream>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/ExecutionEngine/Interpreter.h>
#include <llvm/ExecutionEngine/JIT.h>
@justinvh
justinvh / bf.py
Created January 11, 2014 03:31
stupidly simple C output bf
import sys
preamble = '#include <stdio.h>\nmain(){char a[5000]={0};char *p=a;%s;return 0;}'
cmds = {'>': '++p;', '<': '--p;', '+': '++*p;', '-': '--*p;',
'.': 'putchar(*p);', ',': '*p=getchar();', '[': 'while(*p){', ']': '}'}
print(preamble%(''.join(cmds.get(i, '') for i in sys.stdin.read())))