Skip to content

Instantly share code, notes, and snippets.

@bramses
bramses / indexOf.java
Created July 6, 2018 12:52
Java Implementation of indexOf()
public int indexOf(int ch, int fromIndex) {
if (fromIndex < 0) {
fromIndex = 0;
} else if (fromIndex >= count) {
// Note: fromIndex might be near -1>>>1.
return -1;
}
if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
// handle most cases here (ch is a BMP code point or a
@bramses
bramses / two_functions.py
Created July 6, 2018 21:25
How To test Without Really Trying
def hard_state_add_5(whole_obj):
if "a" in whole_obj:
return whole_obj["a"] + 5
def easy_state_add_5(input_num):
return input_num + 5
def main():
whole_obj = {}
whole_obj["a"] = 10
@bramses
bramses / Menu.js
Created May 30, 2019 17:12
Algolia Custom Component
import React from "react"
const Menu = ({ items, refine, title }) => (
<div>
<p className="star-wars-facet">{title}</p>
<hr className="star-wars-hr"/>
<ul>
{items.map(item => (
<li style={{ listStyle: 'none' }} key={item.value}>
<a href="#" style={{ fontWeight: item.isRefined ? 'bold' : '', textDecoration: 'none' }} className="star-wars-facet" onClick={event => {
@bramses
bramses / algolia-plugin.js
Created May 31, 2019 17:05
Algolia Plugin -- Gatsby
{
resolve: `gatsby-plugin-algolia`,
options: {
appId: process.env.APP_ID,
apiKey: process.env.API_KEY,
indexName: 'star-wars-characters', // for all queries
queries,
chunkSize: 10000, // default: 1000
}
}
@bramses
bramses / galakrond_priest.pde
Created December 15, 2019 06:42
Galakrond Priest Eye 👁
float p1x;
float p1y;
float p2x;
float p2y;
float p3x;
float p3y;
float p4y;
@bramses
bramses / script.pde
Created January 18, 2020 07:42
Disentegrating Mountain [Processing]
/*
fork of P_2_1_2_04
*/
PImage img;
int tileCount = 50;
float tileWidth;
float tileHeight;
int actRandomSeed = 0;
@bramses
bramses / COMDE.md
Created April 17, 2021 19:03
Recursion

index.ts -- low temperature: Typescript

This code is importing the VSCode library and the dotenv library. It also imports OpenAI, which is a library for AI.

import * as vscode from 'vscode'
import * as dotenv from 'dotenv'
// @ts-ignore
import * as OpenAI from '../openai/index.js'
import fetch from 'node-fetch'
@bramses
bramses / add.js
Created August 3, 2021 03:01
the cli test
/* make a function that does basic addition */
function add(a, b) {
return a + b;
}
@bramses
bramses / BinTree.java
Created August 5, 2021 21:00
Silicon Valley Season 1, Episode 6 (15:07)
def _remove_from_parent(self,tr,path):
parent = self._find(tr, path[:-1]
del tr[parent[self.SUBDIRS][path[-1][.key0]
@bramses
bramses / sms.js
Created August 9, 2021 23:05
Receiving a Message on NodeJS with Twilio
router.post('/sms', async (req, res) => {
const twiml = new MessagingResponse();
await workflow(`${req.body.Body}`)
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end('Message Received');
});