Skip to content

Instantly share code, notes, and snippets.

View sharpred's full-sized avatar

Paul Ryan sharpred

View GitHub Profile
import 'package:piota_api/src/config.dart' as appconfig;
import 'dart:io';
import 'package:test/test.dart';
void main() {
test('configfromJson', () async {
final file = File('/Users/paulryan/Documents/projects.nosync/flutter/piota/api/test/fixtures/app_config2.json');
final str = await file.readAsString();
final json = appconfig.configFromJson(str);
//print(str);
@sharpred
sharpred / dart.json
Last active September 14, 2022 08:11
dart code snippet for vscode
{
// Place your snippets for dart here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@sharpred
sharpred / monad.js
Created April 27, 2018 09:38
simple monad
class Monad {
constructor(val) {
this.__value = val;
}
static of(val) {//Monad.of is simpler than "new Monad(val)"
return new Monad(val);
};
map(f) {//Applies the function but returns another Monad!
return Monad.of(f(this.__value));
};
@sharpred
sharpred / fizzBuzz.js
Last active September 14, 2017 13:33
calc fizzbuzz
const fizzBuzz = x => {
let test1 = x % 3 === 0 ? 1 : 0;
let test2 = x % 5 === 0 ? 2 : 0;
return test1 | test2;
};
const printFizzBuzz = (item, val) => {
let x = val + 1;
switch (fizzBuzz(x)) {
case 1:
console.log("Fizz");
@sharpred
sharpred / deliverRegex.js
Last active July 26, 2017 10:44
gets build and revision number from failed deliver job
var regex = /(ERROR ITMS-90189: "Redundant Binary Upload. There already exists a binary upload with build ')([0-9.]{5})(.)([0-9.]{10})(.*)/g;
var str = `ERROR ITMS-90189: "Redundant Binary Upload. There already exists a binary upload with build '1.8.0.1501059235' for version '1.8.0'"`;
var m, version, buildNo;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
@sharpred
sharpred / darkskies.js
Created June 7, 2017 10:15
webtask for dark skies api
'use latest'
module.exports = function (context, cb) {
var request = require("request");
//37.8267
//-122.4233
var url = `https://api.darksky.net/forecast/${context.data.dsApiKey}/${context.data.latitude},${context.data.longitude}?exclude=%5Bminutely,daily,%20%20flags%5D?units=%5Buk2%5D`;
var options = {
method: 'GET',
url: url
};
@sharpred
sharpred / checkrReport.js
Last active May 19, 2017 09:56
checkr webtask
/*
* set a webtask called checkrKey for your API key
*/
module.exports = function (ctx, request, response) {
var request = require("request");
var authKey = 'Basic ' + ctx.secrets.checkrKey;
var url = 'https://api.checkr.com/v1/reports/' + ctx.data.id;
var options = {
method: 'POST',
url: url,
@sharpred
sharpred / webtask1.js
Last active February 20, 2017 16:12
run webtask code with token claims
return function (context, cb) {
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: context.secrets.ACCESS_KEY,
secretAccessKey: context.secrets.SECRET_KEY,
region: 'eu-west-1'
});
var sns = new AWS.SNS();
@sharpred
sharpred / lookup.js
Created January 26, 2017 12:47
use of ramda fantasy Maybe for deep inspection of an object property
/*
* use of ramda fantasy Maybe for deep inspection of an object property
* see https://github.com/ramda/ramda-fantasy/blob/master/docs/Maybe.md
* for more info
*/
const R = require("ramda");
const M = require("ramda-fantasy").Maybe;
const Just = M.Just;
const Nothing = M.Nothing;
const response = {
@sharpred
sharpred / add_bundle.rb
Created January 25, 2017 11:36
use cocoapods xcodeproj gem to add a file to your xcode project from the command line
require 'xcodeproj'
project_path = "./platforms/ios/helloWorld.xcodeproj"
project = Xcodeproj::Project.open(project_path)
#add the bundle as a reference
bundle_path = "../../includes/OTABundle.bundle"
bundleRef = project.new_file(bundle_path);