Skip to content

Instantly share code, notes, and snippets.

View aeisenberg's full-sized avatar
:octocat:

Andrew Eisenberg aeisenberg

:octocat:
View GitHub Profile
@aeisenberg
aeisenberg / Eratosthenes.js
Last active May 6, 2020 15:36
Sieve of Eratosthenes
/**
* This function implements the Sieve of Eratosthenes.
* https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
*
* @param {number} lastNumber The upper bound of the number to check
* @return {number[]} An array of prime numbers less than lastNumber
*/
function sieve(lastNumber = 1000) {
// Create an array and fill it with true
// Important! the array's length is one more than lastNumber so that
@aeisenberg
aeisenberg / VSCODE-CODEQL-in-workspaces.md
Last active March 9, 2022 21:58
How to get codeql working in codespaces

About Codespaces

Codespaces is a product from GitHub that allows users to use a hosted version of VS Code to edit their GitHub repositories online.

Getting CodeQL running in codespaces

  1. Fork the vscode-codeql-starter repo.
  2. Create and open a codespace on the main branch.
    vscode-codeql-starter
  3. Open the workspace file vscode-codeql-starter.code-workspace and make sure codespaces reloads so that it is using that workspace file. (This may happen automatically.)
@aeisenberg
aeisenberg / git-clone-gerrit
Created June 26, 2018 20:53
Clones a repository from gerrit and includes a default /refs/for/* clause
#! /bin/sh -e
server=gerrit.example.com # change to your own server
username=$1
project=$2
url=ssh://${username}@${server}:29418/${project}
git clone ${url}
cd ${project}
git config gerrit.createchangeid true
git config remote.origin.url ${url}
git config remote.origin.push HEAD:refs/for/master
import java.util.Collection;
public class Ambiguity {
public void foo(CriteriaBuilder builder) {
// change Object -> Number (or any other type) and it compiles
Expression<Object> objectExpression = null;
Expression<Collection<Object>> collectionOfObjectExpression = null;
builder.isNotMember(objectExpression, collectionOfObjectExpression);
}
@aeisenberg
aeisenberg / evernote-migration.scpt
Created May 31, 2016 03:05
Use this apple script to migrate your files out of evernote and into notes.app.
tell application "Evernote"
set _Notebooks to every notebook
repeat with _NoteBook in _Notebooks
set _NoteBookName to name of _NoteBook
set _Notes to every note of _NoteBook
@aeisenberg
aeisenberg / path-count.js
Last active May 15, 2016 03:01
Here is a generalized solution to the [path-counting brain teaser from Kahn Academy](https://www.khanacademy.org/math/math-for-fun-and-glory/puzzles/brain-teasers/v/3-d-path-counting-brain-teaser). You can run this in node passing the size and number of dimensions as arguments.
// argv: size, dims
'strict mode';
var size = process.argv[2];
var dims = process.argv[3];
var grid = initializeGrid(size, dims);
setValueAt(createArray(dims, 0), grid, 1);
var initialLoc = createArray(dims, size-1);
@aeisenberg
aeisenberg / nested_scopes2.html
Created August 1, 2014 20:33
Nested scopes in angular behave strangely because of prototypal inheritance.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
angular.module('watchingApp', [])
.controller('watchedController', function($scope) {
$scope.value = 9;
})
.directive('watching', function() {
@aeisenberg
aeisenberg / nested_scopes.html
Last active August 29, 2015 14:04
Nested scopes in angular behave strangely because of prototypal inheritance.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js"
type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
angular.module('watchingApp', [])
.controller('watchedController', function($scope) {
$scope.value = 9;
})
@aeisenberg
aeisenberg / not_modular.html
Last active August 29, 2015 14:04
Angular apps are not modular
<!DOCTYPE html>
<html ng-app="parent">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js"
type="text/javascript"></script>
<script type="text/javascript">
angular.module('sub1', [])
.run(function(sub2Value) {
console.log(sub2Value);
@aeisenberg
aeisenberg / ClosureWriter.java
Created June 7, 2013 04:39
Where's the memory leak?
public class ClosureWriter {
protected interface UseExistingReference {}
public void writeClosure(ClosureExpression expression) {
// create some byte-code
// ...
expression.setNodeMetaData(ClosureWriter.UseExistingReference.class,Boolean.TRUE);
// do some more byte-code writing