Skip to content

Instantly share code, notes, and snippets.

@naranjja
naranjja / element.js
Created April 25, 2018 22:49
Local data implementation for master-detail view in NativeScript
let { fileSystemService } = require("./fileSystemService")
fileSystemService = new fileSystemService("list.json")
const frame = require("ui/frame")
exports.onLoaded = (args) => {
const page = args.object
page.bindingContext = page.navigationContext.model
}
@naranjja
naranjja / page.xml
Created April 24, 2018 22:08
Popup implementation in NativeScript
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="onLoaded" navigatedTo="onNavigatedTo" actionBarHidden="true">
<Button id="bOpenPopup" text="Open popup" tap="onOpenPopupTap" />
</Page>
@naranjja
naranjja / detail.js
Last active April 23, 2018 23:26
Master-detail implementation in NativeScript
const observable = require("data/observable")
const frame = require("ui/frame")
let data
exports.onLoaded = (args) => {
const page = args.object
const { index } = page.navigationContext
data = page.navigationContext.model
page.bindingContext = data.profiles.getItem(index)
@naranjja
naranjja / user.js
Last active April 23, 2018 14:11
Access databound properties in NativeScript
const observable = require("data/observable")
exports.onLoaded = (args) => {
const page = args.object
// basically an observable constructor
const user = new observable.fromObject({
name: "Jose Naranjo",
year: 1992,
month: 11,
@naranjja
naranjja / page.js
Created April 23, 2018 13:03
Databinding in NativeScript example
const observable = require("data/observable")
const view = require("ui/core/view")
// some isolated observable and listener
const user = new observable.Observable()
user.set("Name", "Jose")
user.on("propertyChange", function (eventData) {
console.log(`The user's current name is ${eventData.object.Name}`)
})
user.set("Name", "Antonio")
@naranjja
naranjja / page1.xml
Created April 20, 2018 23:21
NativeScript bottom tab navigation
<Page>
<TabView androidTabsPosition="bottom">
<TabViewItem title="Go to Page 1">
<StackLayout>
<Label text="Welcome to Page 1" />
</StackLayout>
</TabViewItem>
<TabViewItem title="Go to Page 2">
<Frame defaultPage="views/page2/page2" />
</TabViewItem>
@naranjja
naranjja / custom_stopwords.txt
Created April 20, 2018 21:36
Simple implementation of word2vec to find related words within a dataset
some
stop
words
@naranjja
naranjja / cast-bools-to-ints.py
Created April 20, 2018 16:56
Some Python/Pandas/Jupyter tricks
# effecitvely cast boolean to integer
df3['species'] = df3['species'] * 1 # operating on series overcharges, lambda all over series, True * 1 = 1, False * 1 = 0
df3.head()
@naranjja
naranjja / requirements.txt
Last active April 20, 2018 21:14
Simple implementation of topic modelling using NMF and LDA
sklearn>=0.18.2
nltk>=3.2.3
@naranjja
naranjja / replace-if-regex-match.py
Created April 20, 2018 15:58
A way to make string replacements upon regular expression matches.
import re
strings = [
'/i wish this were html and not markdown.md',
'/yeah/me/too.md'
]
for s in strings:
print(re.sub(r'\/(.+).md', r'\1.html', s))
# /i wish this were html and not markdown.html