Skip to content

Instantly share code, notes, and snippets.

View tomfa's full-sized avatar

Tomas Fagerbekk tomfa

View GitHub Profile
@tomfa
tomfa / gist:12bf7651d6a346eb2942
Last active August 29, 2015 14:13
jQuery confirm dialog using Bootstrap
/*
* jQuery confirm modal using bootstrap 3.0 (might work with other, shrug)
*
* Usage:
* var otherFunction = function(){
* funkyDialogBox(
* "Will you marry me",
* function(){ console.log('She said YES! :D'},
* function(){ console.log('She said no :(')
* }
@tomfa
tomfa / gist:091ec7b23f0af27e693d
Created February 3, 2015 15:35
Basic Post request with jQuery
$.ajax({
type: 'POST',
data: {
'datalabel1': data_1,
'datalabel2': data_2
},
url: '/where/to/post',
success: function(data) {
console.log("SUCCESS:")
console.log(data)
@tomfa
tomfa / JSON-intArray-converter.js
Created May 10, 2015 11:22
JSON to 8-bit-integer parsing (and visa versa)
// JSON to Uint8Array parsing and visa versa
// (Intended Bluetooth communication on Cordova)
var JsonToArray = function(json)
{
var str = JSON.stringify(json, null, 0);
var ret = new Uint8Array(str.length);
for (var i = 0; i < str.length; i++) {
ret[i] = str.charCodeAt(i);
}
@tomfa
tomfa / VBscript doc etc. to docx etc.
Last active October 2, 2015 13:46
VBscript that saves Office binary files as OpenXML formats, e.g. doc to dox. Either single files or recursive through subfolders. Office >= 2007 must be installed for this to work. 1) Save as converter.vbs 2) Go to folder i cmd. 3) Run with "cscript converter.vbs path/to/folder"
Dim arguments
Set arguments = WScript.Arguments
' http://msdn2.microsoft.com/en-us/library/bb238158.aspx
Const wdFormatXMLDocument = 12 ' docx
' https://technet.microsoft.com/en-us/library/ff198017.aspx
Const xlOpenXMLWorkbook = 51 ' xlsx
' https://msdn.microsoft.com/en-us/library/office/ff746500.aspx
Const ppSaveAsOpenXMLPresentation = 24 ' pptx
@tomfa
tomfa / django-on-heroku.sh
Last active December 19, 2015 23:50
Django in virtualenv on heroku. Initiates a python virtualenv, installs django and creates a heroku instance where it runs. Run this script from terminal with: sh django-on-heroku.sh
#!/bin/bash
# Requires python, pip, virtualenv
# which can be installed with brew install python
# (See brew.sh for brew installation)
bold=$(tput bold)
normal=$(tput sgr0)
function trueFalseInput {
// nodejs freshdesk implementation
var request = require('request');
var url = "http://yourcompanyname.freshdesk.com"; // Your URL
var apikey = ""; // Your API key
var auth = 'Basic ' + new Buffer(apikey + ':X').toString('base64');
var fresh = {
get: function(link, callback) {
@tomfa
tomfa / website-static.json
Created December 20, 2015 19:09
Cloudfront config for use with awscli (suitable for staticfiles for websites - stored in a S3 bucket). Replace "[[YOUR-BUCKET-NAME]]"
{
"DistributionConfig": {
"Comment": "",
"CacheBehaviors": {
"Quantity": 0
},
"Logging": {
"Bucket": "",
"Prefix": "",
"Enabled": false,
@tomfa
tomfa / testsms.py
Created December 27, 2015 00:34
SMS sending using pushbullet
'''
1) Sign up for pushbullet @ pusbullet.com
2) Install the pushbullet app on your phone
3) Find your API key here: https://www.pushbullet.com/#settings/account
4) Install pushbullet with 'pip install pushbullet.py'
5) Replace 'key' value below
'''
from pushbullet import Pushbullet
@tomfa
tomfa / index.html
Created July 20, 2016 12:24
Download svg as png (or svg) with Java backend support
<form method="POST" action="http://localhost:2222/rest/download/png" onSubmit="getSvg(this)">
<input type="hidden" value="" name="data" type="text" />
<button type="submit">GO</button>
</form>
<div class="svg-wrapper">
<svg height="140" width="500">
<ellipse cx="200" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" />
</svg>
</div>
@tomfa
tomfa / index.html
Created July 20, 2016 12:27
Download svg as png (or svg) with Java backend support
<form method="POST" action="http://localhost:2222/rest/download/png" onSubmit="getSvg(this)">
<input type="hidden" value="" name="data" type="text" />
<button type="submit">GO</button>
</form>
<div class="svg-wrapper">
<svg height="140" width="500">
<ellipse cx="200" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" />
</svg>
</div>