Skip to content

Instantly share code, notes, and snippets.

@AllanGraves
AllanGraves / VarInput.js
Created February 4, 2021 18:52
Context Consumer
const InputModal = {variableIndex} => {
const keyText = useContext(LocationContext);
return(
<TouchableHighlight
style={styles.openButton}
onPress={() => {
//console.log('modalText: ' + modalText);
changeText(modalText);
setModalVisible(!modalVisible);
console.log('keyText: ' + keyText[variableIndex]);
@AllanGraves
AllanGraves / model.py
Created February 3, 2021 17:12
DCGan Model for DCGAN Tutorial
class Generator(nn.Module):
def __init__(self, ngpu):
super(Generator, self).__init__()
self.ngpu = ngpu
self.main = nn.Sequential(
# input is Z, going into a convolution
nn.ConvTranspose2d( nz, ngf * 8, 4, 1, 0, bias=False),
nn.BatchNorm2d(ngf * 8),
nn.ReLU(True),
# state size. (ngf*8) x 4 x 4
const LocationScreen = ({route, navigation}) => {
let variables = route.params.story.variables;
useEffect(() => {
/* Override variables passed in with anything loaded from AsyncStorage */
variables = getData(route.params.storyID, variables);
}, []);
console.log('LocationScreen: ' + JSON.stringify(variables));
return (
@AllanGraves
AllanGraves / App.js
Created January 19, 2021 18:11
Displaying our individual components from regexifyString in a ordered text.
let textToDisplayArray = ParserClass.parseVariables(text);
let textList = textToDisplayArray.map((item) => {
if (typeof item !== 'string') {
return item;
} else {
return <Text>{item}</Text>;
}
});
@AllanGraves
AllanGraves / App.js
Last active January 19, 2021 17:57
Embedding Text
let textList = textToDisplayArray.map((item) => {
if (typeof item !== 'string') {
return item;
} else {
return <Text>{item}</Text>;
}
});
return <Text>{textList}</Text>;
@AllanGraves
AllanGraves / App.js
Created January 19, 2021 16:58
regexifyString example
const result = regexifyString({
pattern: /{var .*}/gim,
decorator: (match, index) => {
console.log(match);
let textToDisplay = match.slice(4, -1);
return <VarInput inputText={textToDisplay} key={index} />;
},
input: text,
});
@AllanGraves
AllanGraves / App.js
Created January 19, 2021 16:52
Composition of our sentence
<Text> Hello
<Pressable
onPress={() => {
console.log('foo!');
}}>
<Text>
Hello <Text style={{color: 'red'}}> you again </Text>
</Text>
</Pressable>
</Text>
@AllanGraves
AllanGraves / Locations.js
Last active January 17, 2021 12:06
Changing default location using an effect
const Location = ({jsondata, locationID, storyID}) => {
useEffect(() => {
console.log('Resetting default location');
setLocation(0);
}, [storyID]);
@AllanGraves
AllanGraves / Locations.js
Created January 17, 2021 11:54
adding a cleanup (componentWillUnmount) log message.
useEffect(() => {
console.log(
`Location:IN MOUNT:
LocationID: ${locationID} + StoryID: ${storyID} + curLocation: ${curLocation}`,
);
return () => {
console.log('Location: CleaningUP');
};
}, []);
@AllanGraves
AllanGraves / Locations.js
Created January 15, 2021 20:14
Showing a useEffect hook to print when the component is mounted.
useEffect(() => {
console.log(
`Location:IN MOUNT:
LocationID: ${locationID} + StoryID: ${storyID} + curLocation: ${curLocation}`,
);
});