Skip to content

Instantly share code, notes, and snippets.

View rms1000watt's full-sized avatar

Ryan M Smith rms1000watt

View GitHub Profile
@rms1000watt
rms1000watt / js-ajax-download.jsx
Created June 22, 2016 17:24
Javascript AJAX to server then download PDF
// This is an incomplete example but has the gist of it
successCB = (blob) => {
let objectURL = URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = objectURL;
a.download = 'MyPDF';
document.body.appendChild(a);
a.click();
setTimeout(()=>{a.remove()}, 1000);
@rms1000watt
rms1000watt / js-save-html-img.jsx
Created June 22, 2016 17:32
Javascript save HTML div as img
// This example uses ReactJS but can be substituted for something else. Uses html2canvas and FileSaver.
// This example saves a leaflet map
saveMap = () => {
let mapNode = ReactDOM.findDOMNode(this.refs.leafletMap)
html2canvas(mapNode, {
useCORS: true,
onrendered: (canvas) => {
canvas.toBlob((blob) => {
FileSaver.saveAs(blob, "MyMap.png");
@rms1000watt
rms1000watt / reactjs-dropzone-example.jsx
Last active June 22, 2016 18:33
ReactJS Dropzone Example
// http://stackoverflow.com/questions/4212861/what-is-a-correct-mime-type-for-docx-pptx-etc
// https://technet.microsoft.com/en-us/library/ee309278(office.12).aspx
import Dropzone from 'react-dropzone';
import Button from 'react-bootstrap/lib/Button';
const acceptedMimeTypes = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel";
...
@rms1000watt
rms1000watt / python-install-brew-node-npm.py
Created July 11, 2016 13:50
Python script to uninstall & install Homebrew, Nodejs, and NPM to latest
import os
# Uninstall node and all node packages (will require `npm install` on your projects again)
os.system('brew uninstall node')
os.system('sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules')
os.system('sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*')
# Install brew, node, npm
os.system('/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"')
os.system('brew install node')
@rms1000watt
rms1000watt / python-extract-after-scrape.py
Created July 13, 2016 15:31
Python script to extract phone numbers and emails from html pages that were web scraped
import re
import glob
def main():
outputFile = 'output.tsv'
files = glob.glob('*.html')
print "Extracting from %s files" %(len(files))
data = []
@rms1000watt
rms1000watt / python-wireshark-hex-to-ascii.py
Created July 13, 2016 15:40
Python script to convert Wireshark Hex output to ASCII
def main():
packet = "|dc|ef|09|b0|e8|ba|ac|bc|32|91|f2|93|08|00|45|00|00|68|d8|73|40|00|40|06|4a|cd|c0|a8|01|07|95|38|c0|67|f5|62|0b|b9|3a|03|1d|1d|8f|c2|52|1d|80|18|10|15|64|61|00|00|01|01|08|0a|4e|2a|51|99|00|e4|c8|7e|03|00|00|34|2f|e0|00|00|00|00|00|43|6f|6f|6b|69|65|3a|20|6d|73|74|73|68|61|73|68|3d|67|6c|6f|77|63|6c|6f|75|64|5c|66|72|65|64|0d|0a|01|00|08|00|0b|00|00|00|"
packet = ''.join(packet.split('|'))
print packet.decode("hex")
if __name__ == '__main__':
main()
@rms1000watt
rms1000watt / python-tornado-server.py
Created July 15, 2016 17:15
Basic Python Tornado Server
import tornado.web
import tornado.escape
import tornado.ioloop
def main():
application = tornado.web.Application([
(r'/data', DataHandler),
(r'/ping', PingHandler)
])
@rms1000watt
rms1000watt / github-remove-ds_store.sh
Created July 17, 2016 16:08
Remove .DS_Store if you forgot to add it to your .gitignore initally
# http://stackoverflow.com/questions/107701/how-can-i-remove-ds-store-files-from-a-git-repository
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
@rms1000watt
rms1000watt / python-printJS-in-pdf.py
Last active March 29, 2024 11:24
Python script to add JS to pdf so the pdf will print immediately when opened
# IE users need: https://get.adobe.com/reader/
from PyPDF2 import PdfFileWriter, PdfFileReader
output = PdfFileWriter()
ipdf = PdfFileReader(open('old.pdf', 'rb'))
for i in xrange(ipdf.getNumPages()):
page = ipdf.getPage(i)
output.addPage(page)
@rms1000watt
rms1000watt / html-stimulsoft-frontend-nodejs.html
Created July 18, 2016 18:21
The missing HTML code for NodeJS backend connecting to SQL DB with Stimulsoft
<!-- The missing piece for: https://github.com/stimulsoft/Samples-JS/tree/master/Node.js/04.%20Start%20SQL%20Adapters%20from%20Http%20Server -->
<html>
<head>
<link href="stimulsoft.viewer.office2013.css" rel="stylesheet">
</head>
<body>
<h4>Hello World</h4>
<script src="stimulsoft.reports.js" type="text/javascript"></script>