Skip to content

Instantly share code, notes, and snippets.

View danibrear's full-sized avatar
🤓

Danielle "Dani" Brear danibrear

🤓
View GitHub Profile
@danibrear
danibrear / example-migration.js
Last active April 7, 2021 21:49
This is an example migration for adding a status attribute to a hypothetical Todo table.
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* How to run:
* - export AWS_PROFILE
* - export AWS_REGION=us-east-1
*/
const DynamoDB = require("aws-sdk/clients/dynamodb");
const dynamodb = new DynamoDB();
const DocumentClient = new DynamoDB.DocumentClient();
@danibrear
danibrear / Example.ts
Last active December 3, 2020 13:53
Amplify Auth Field-Level Authorization Example
// From https://docs.amplify.aws/cli/graphql-transformer/auth#field-level-authorization
// The code where this exception is thrown is: https://github.com/aws-amplify/amplify-js/blob/d9aa32837f15f408daba0a0104bb27042b9331da/packages/api-graphql/src/GraphQLAPI.ts#L314
type User @model {
id: ID!
username: String
ssn: String @auth(rules: [{ allow: owner, ownerField: "username" }])
}
@danibrear
danibrear / Chunk Single Line
Created December 11, 2018 23:45
Wanted to see if I could do it.
const chunk = (arr, size) => arr.reduce((a, n) => a[a.length-1].length < size ? [...a.slice(0,-1), [...a[a.length-1], n]] : [...a, [n]], [[]]);
const a = [1,2,3,4,5,6,7,8,9]
console.log(chunk(a, 2)); // -> [[1, 2], [3, 4], [5, 6], [7, 8], [9]]
console.log(chunk(a, 3)); // -> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
console.log(chunk(a, 4)); // -> [[1, 2, 3, 4], [5, 6, 7, 8], [9]]
from probability_solution import (
make_power_plant_net,
set_probability,
get_alarm_prob,
get_gauge_prob,
get_temperature_prob,
get_marginal_temp_prob,
get_game_network,
calculate_posterior,
Gibbs_sampler,
@danibrear
danibrear / App.js
Created August 12, 2016 13:13
React Redux with Child Context
import React, { Component, PropTypes } from 'react';
import logo from './logo.svg';
import './App.css';
import { connect } from 'react-redux';
const mapStateToProps = (state) => ({
name: state.name,
});
@danibrear
danibrear / 0_reuse_code.js
Created April 12, 2016 17:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@danibrear
danibrear / Att Decryption Code.py
Last active August 29, 2015 14:25
Att Decryption
letters = [ l for l in 'abcdefghijklmnopqrstuvwxyz']
sentence = 'Rz xvi jigt nzz v ncjmo ydnovixz vczvy, wpo rz xvi nzz kgziot oczmz ocvo izzyn oj wz yjiz. - Vgvi Opmdib'
def decrypt(letter):
if letter not in letters: return letter
return letters[((letters.index(letter) + 5) % len(letters))]
for word in sentence.split(' '):
print ''.join([decrypt(letter) for letter in word.lower()]),
# we can only see a short distance ahead, but we can see plenty there that needs to be done. - alan turing
@danibrear
danibrear / gist:660cd8b9c84db32ff7aa
Created May 28, 2015 21:00
Add a method to Array to zero all the elements.
Array.prototype.zeros = function() { return Array.apply(null, {length: this.length}).map(function(x){ return 0;}); };
@danibrear
danibrear / Addition&Subtraction without + or -
Created May 11, 2015 13:17
Just wanted to play around with creating addition and subtraction methods without using + and -
/*
Just wanted to play around with creating addition and subtraction methods without using + and -
@author: David Brear
@date: 2015-05-11
*/
var add = function (x, y) {
while (y !== 0) {
var carry = x & y;
x = x ^ y;
function sudoku(puzzle) {
if (solved(puzzle)) {
return puzzle;
}
var copy = puzzle.slice(0);
for(var x=0;x<9; x++) {
for(var y=0;y<9;y++) {
if (puzzle[x][y] !== 0) continue;
var available = get_available(puzzle, x,y);
for(var i = 0; i < available.length;i++) {