Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@davidsharp
davidsharp / proxied-simple-store.js
Created March 8, 2017 10:40
An ill-advised proxy wrapper snippet for react-native-simple-store (needs a proxy polyfill)
import store from 'react-native-simple-store';
//also requires something like 'proxy-polyfill'
export default new Proxy(store, {
//GET is async, so it's used like `myStore[someID].then(...)`
get: async function (receiver, name) {
return await receiver.get(name)
},
//SET simply works like `myStore[someID]=someObject`
// (`null` deletes, this lines up with calling for a non-existant value)
@davidsharp
davidsharp / puni-scrape.js
Last active March 30, 2017 14:57
A naive (WIP & incomplete) PuniPuniJapan scraper
const cheerio = require('cheerio'),
request = require('request'),
dance = require('breakdance'),
fs = require('fs'),
path = require('path'),
url = require('url')
const save_loc = path.resolve(process.argv[1],'..','puni-scrape'); //configurable?
const puni = 'http://www.punipunijapan.com';
@davidsharp
davidsharp / kanahave.js
Last active May 18, 2025 00:47
A quick, dirty script for getting the hiragana/katakana for 1, 2 or 3 character romaji strings
//export default kanahave = (input,script='h') => {
const kanahave = (input,script='h') => {
let kI = kanaInput(input);if(kI)return kI;
script=script.toLowerCase()
const kana = script=='hiragana'||script.charAt(0)=='h'?data.hiragana:data.katakana
return romajiInput(input,kana)
}
const kanaInput = k => {
let h_i = data.hiragana.join('').indexOf(k.charAt(0))
@davidsharp
davidsharp / jisho.js
Last active March 28, 2017 12:04
Quickly thrown together CLI tool for Jisho requests
const cmdr = require('commander'),
request = require('request')
cmdr
.option('-t, --text [value]')
.option('-c, --common')
.parse(process.argv);
const Jisho = 'http://jisho.org/api/v1/search/words?keyword='
@davidsharp
davidsharp / react-amsterdam-schedule.js
Last active April 19, 2017 12:31
Quickly ripped apart `puni-scrape.js` to throw together a scraper to get a markdown react.amsterdam schedule
const cheerio = require('cheerio'),
request = require('request'),
dance = require('breakdance'),
fs = require('fs'),
path = require('path'),
url = require('url')
const save_loc = path.resolve(process.argv[1],'..');
const r_a = 'https://react.amsterdam';
@davidsharp
davidsharp / react-amsterdam-timetable.md
Created April 6, 2017 14:17
The timetable for react.amsterdam in glorious Markdown [Output from react-amsterdam-timetable.js]
TIME REACT NATIVE
08:00 ** Registation ** ** **
08:30 ** Welcome Breakfast by Kega ** ** **
09:30 Conference opening ** **
09:50 **Styling React/ReactNative Applications – Max Stoiber KeystoneJS ** **Coding Mobile with the Pros – Gant Laborde Infinite Red **
React popularized a new way of building user interfaces – components. By splitting our app into small, digestible parts the system as a whole becomes a lot easier to understand. CSS was made in an era where documents were the height of the web. It doesn't fit easily into component-based systems, making styling one of the pa
@davidsharp
davidsharp / rubbish-csv-to-json.js
Last active April 6, 2017 16:14
I had some 'incorrectly' formatted CSVs that I wanted to read in a different way
#!/usr/bin/env node
'use strict';
const path = require('path');
const fs = require('fs');
const cmdr = {path:process.argv[process.argv.length-1]}
console.log('Manipulating : '+cmdr.path);
if(!cmdr.path){console.log('No path given');process.exit();}
@davidsharp
davidsharp / react-debugger-tube.js
Last active May 19, 2017 08:46
Quick console drop in for Youtube videos in React Debugger
// Is this _even_ gist-worthy? (Not yet, is the answer. Not yet.)
window.youtubeMe = function(videoID){
document.querySelector(".content")
.insertAdjacentHTML('beforebegin',
'<iframe width="100%" height="100%" src="https://www.youtube.com/embed/'+videoID+'" frameborder="0" allowfullscreen></iframe>'
);
}
document.querySelector("body").style.color="white"
document.querySelector("body").style['background-color']="black"
@davidsharp
davidsharp / rn-debugger-style-drop.css
Last active May 25, 2017 11:37
Gonna write something that automates this, but drop this (c+p) into `./node_modules/react-native/local-cli/server/util/debugger.html`
body {
font-family: "Fira Code", "Courier New", monospace;
font-size: large;
font-weight: 200;
margin: 0;
padding: 0;
color: white;
background-color: black;
background: linear-gradient(15deg, #44dd44, #dddd44);
height: 100vh;
@davidsharp
davidsharp / clip-circle.js
Last active July 19, 2019 11:25
Quick PNG circle clipper
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const cmdr = require('commander');
//this requires Cairo: https://www.npmjs.com/package/canvas
// brew install pkg-config cairo libpng jpeg giflib
const {createCanvas, Image} = require('canvas');
cmdr