Skip to content

Instantly share code, notes, and snippets.

@seth10
seth10 / ClickGetImg_Object.js
Last active August 7, 2016 19:57
Alternate approaches for handling multiple changing styles of spotlight in snipmodeClickHandler
var clickGetImg = (function() {
var count = 3;
return function(event) {
count--;
if(event.target.src) {
chrome.runtime.sendMessage({image: event.target.src});
count = -1;
}
if(count <= 0){
@seth10
seth10 / chapter_num.js
Created August 28, 2016 19:52
Use the current chapter number in the callback with let to keep the value at that time
for(var n = 1; n <= fic_info['max_chapters']; n++) {
let n_ = n;
getChapter(fic_info['url']+n, function(page) {
(chrome.extension.getBackgroundPage()).addChapter(page, n_, fic_info['max_chapters']);
});
}
@seth10
seth10 / print_array_type_string.js
Created August 28, 2016 20:27
Print an array containing a boolean for if each chapter is a string (false being undefined, getChapter has not loaded it yet) every call to addChapter
chaptersStringiness = []
for(var i = 0; i < max_chapters; i++)
chaptersStringiness[i] = typeof(chapters[i])=="string";
console.log(chaptersStringiness);
@seth10
seth10 / quote_regex.md
Last active October 8, 2022 03:30
A record of all the regular expressions I tried to match single and double quotes for LaTeX in FicBot

Single quotes

  1. / '([A-Za-z ]+)'(?=[^A-Za-z])/g -> `$1'

    Find a quote preceded by a space. Capture one or more letters or spaces. Find another quote. Lookahead to find a character that is not a letter. If the character following the last quote were a letter, it would be a contraction. The replacement string should have a leading space because we do capture a space before the first quote.

  2. /(\s|{)(?:')(.+?)(?:')(\s|})/g -> $1`$2'$3

    First big new attempt, see detailed explanation at 675e6a1. Capture a whitespace character or opening brace (from an italics or bold LaTeX command). Match a quote. Capture one or more of any character, but the least amount possible. Match a quote. Capture a whitespace character or closing brace. Put it back together with the captured whitepsace or braces at the ends and captured text between new quotes.

@seth10
seth10 / screeps_absolute_positioning_test.js
Last active September 19, 2016 02:09
Trying to figure out storing absolute positions in Screeps. Turns out you could use ids for this, but shouldn't.
> Game.creeps.Snowflake1.pos.findClosestByRange(FIND_SOURCES)
< [source #579fa8b80700be0674d2e2e8]
> Game.creeps.Snowflake1.room.find(FIND_SOURCES)
< [source #579fa8b80700be0674d2e2e8]
> Game.creeps.Snowflake1.room.find(FIND_SOURCES)[0].pos
< [room W53N6 pos 14,42]
> new RoomPosition(14, 42, 'W53N6')
< [room W53N6 pos 14,42]
> new RoomPosition(14, 42) // room required
//Error: invalid arguments in RoomPosition constructor
> JSON.stringify(Game.spawns['Arendelle'].pos.findPathTo(Game.spawns['Arendelle'].room.find(FIND_SOURCES)[0]).length)
< 11
> JSON.stringify(Game.spawns['Arendelle'].pos.getRangeTo(Game.spawns['Arendelle'].room.find(FIND_SOURCES)[0]))
< 12
> JSON.stringify(Game.spawns['Arendelle'].pos.getRangeTo(Game.flags['AdjoiningRoomSource']))
< null // should be path to exit
> PathFinder.search(Game.spawns['Arendelle'].pos, Game.flags['AdjoiningRoomSource'].pos).path.length
< 70 // valid, I counted about 68
> PathFinder.search(Game.spawns['Arendelle'].pos, Game.spawns['Arendelle'].room.find(FIND_SOURCES)[0].pos).path.length
@seth10
seth10 / PiStormsAP.sh
Created September 27, 2016 20:55
Make a PiStorms host an access point to control it from your phone directly
#!/bin/bash
# update list of available packages
sudo apt-get -y update
# hostapd - This is the package that allows you to use the built in WiFi as an access point
# dnsmasq - This is a combined DHCP and DNS server that's very easy to configure
sudo apt-get -y install dnsmasq hostapd
echo -e "\ndenyinterfaces wlan0" >> /etc/dhcpcd.conf
@seth10
seth10 / scr.py
Created October 3, 2016 17:41
Calculate optimal configuration for Screeps creeps
import math
def roundUp(x,y):
return int(math.ceil(float(x)/y))
d = input('Distance: ') #10 #distance of path betweem source and controller
SPAWN_ENERGY_CAPACITY = 300
CONTROLLER_STRUCTURES = { "extension": { 3: 10 } }
STRUCTURE_EXTENSION = "extension"
EXTENSION_ENERGY_CAPACITY = { 3: 50 }
@seth10
seth10 / battery_indicator_coordinates.py
Created October 7, 2016 15:19
A summary of how the coordinates for the battery indicator in the PiStorms browser were derived
# trial and error
scrn.fillRect(x=293, y=180, width=13, height=20, fill=batteryFill, display=False)
scrn.fillRect(x=293+3, y=180-3, width=13-3*2, height= 3, fill=batteryFill, display=False)
scrn.drawAutoText("%.1f V" % (mindsensors_i2c(0x34 >> 1).readByte(0x6E)*.040), xpos+width+(scrn.PS_SCREENHEIGHT-(xpos+width))/2, y=initialYpos+height*4-16, size=16, display=False)
# substituting with how I got these numbers
scrn.fillRect(x=xpos+width+(scrn.PS_SCREENHEIGHT-(xpos+width)-13)/2, y=initialYpos+height*4-16-1-20-5, width=13, height=20, fill=batteryFill, display=False)
scrn.fillRect(x=xpos+width+(scrn.PS_SCREENHEIGHT-(xpos+width)-13)/2+3, y=initialYpos+height*4-16-1-20-5-3, width=13-3*2, height= 3, fill=batteryFill, display=False)
scrn.drawAutoText(("%1.1f V" if battVoltage < 10 else "%2.0f V") % battVoltage, xpos+width+6, y=initialYpos+height*4-16-1, size=16, display=False)