Skip to content

Instantly share code, notes, and snippets.

View perry-mitchell's full-sized avatar

Perry Mitchell perry-mitchell

View GitHub Profile
@perry-mitchell
perry-mitchell / vulpes-setup.js
Last active March 28, 2019 07:31
Task automation blog post - 2019-03-28
const { Service } = require("vulpes");
// Create a new service
const service = new Service(); // Service takes an optional storage parameter
// Initialise the service
await service.initialise();
@perry-mitchell
perry-mitchell / miner.js
Last active January 9, 2018 10:35
ZEC/Flypool Mining monitor
const fetch = require("node-fetch");
const chalk = require("chalk");
const prettyMs = require("pretty-ms");
const VError = require("verror");
const pruddy = require("pruddy-error");
const API = "https://api-zcash.flypool.org";
const DELAY = 60;
const MINER = "t1R21Uq3HQRiyj6ff1kFQcPusqPXiBaAc2U";
//const PAYOUT_MIN = 0.03;
@perry-mitchell
perry-mitchell / element-offset.js
Created December 8, 2017 08:59
True element offset (from document) calculation with debouncing/memoization
import mem from "mem";
const ELEMENT_STYLE_CACHE_TIME = 3000;
let __memoizedGetElementStyle;
export function getElementOffset(target) {
__memoizedGetElementStyle = __memoizedGetElementStyle || mem(getElementStyle, { maxAge: ELEMENT_STYLE_CACHE_TIME });
const boundingRect = target.getBoundingClientRect();
const bodyStyle = __memoizedGetElementStyle(document.body);
RCT_EXPORT_METHOD(generateUUIDs:(RCTResponseSenderBlock)callback) {
NSArray *uuidArr = [BCCrypto generateUUIDsForCount:50];
callback(@[
[NSNull null],
[uuidArr componentsJoinedByString:@","]
]);
}
@perry-mitchell
perry-mitchell / encrypt-string.objectivec.m
Created November 7, 2017 10:47
Encrypt a string in Objective-C
+ (NSString *)encryptText:(NSString *)text withKey:(NSString *)key andSalt:(NSString *)salt andHMAC:(NSString *)hmacHexKey {
// Validation
if (key.length != 64) {
return @"Error:Invalid key length";
} else if (hmacHexKey.length != 64) {
return @"Error:Invalid authentication information or possible tampering";
}
// Data prep
NSString *iv = [BCCrypto generateIVHex];
NSData *ivData = [BCHelpers dataFromHexString:iv];
@perry-mitchell
perry-mitchell / encrypt-string.android.java
Created November 7, 2017 10:46
Encrypt a string in Java for Android
public static String encryptText(String text, String keyHex, String saltHex, String hmacHexKey) {
String ivHex = generateIV();
byte[] ivData = BCHelpers.hexStringToByteArray(ivHex);
byte[] keyData = BCHelpers.hexStringToByteArray(keyHex);
byte[] hmacKeyData = BCHelpers.hexStringToByteArray(hmacHexKey);
IvParameterSpec iv = new IvParameterSpec(ivData);
SecretKeySpec skeySpec = new SecretKeySpec(keyData, "AES");
try {
// AES encryption
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
@perry-mitchell
perry-mitchell / subtlecrypto-importkey.js
Created November 7, 2017 10:23
Import key with SubtleCrypto
subtleCrypto.importKey(
"raw",
stringToArrayBuffer(password),
{ name: "PBKDF2" },
false, // not extractable
["deriveBits"]
)
@perry-mitchell
perry-mitchell / package.json
Created September 19, 2017 05:36
Prettier on commit configuration
{
"name": "project",
"version": "0.0.0",
"scripts": {
"format": "prettier --tab-width 4 --print-width 120 --write 'source/**/*.js'",
"precommit": "lint-staged",
"test": "echo \"nothing yet\"",
"test:format": "prettier-check --tab-width 4 --print-width 120 'source/**/*.js'"
},
"lint-staged": {
@perry-mitchell
perry-mitchell / linda-dynamic-challenge.js
Created September 10, 2017 14:55
Linda Dynamic Challenge
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
const firstNames = ["Perry", "Linda", "Tom", "Noora", "Daniel"];
const lastNames = ["Mitchell", "Damario", "Jerry", "Suojansalo", "Bailo"];
function getName() {
const numFirstNames = firstNames.length;
const numLastNames = lastNames.length;
@perry-mitchell
perry-mitchell / nightmare_preload.js
Last active August 28, 2017 06:43
Nightmare Preload
window.__nightmare = {};
__nightmare.ipc = require('electron').ipcRenderer;
__nightmare.sliced = require('sliced');
// Listen for error events
window.addEventListener('error', function(e) {
__nightmare.ipc.send('page', 'error', e.message, e.error.stack);
});
(function(){