Skip to content

Instantly share code, notes, and snippets.

View afaur's full-sized avatar

Adam Faur afaur

View GitHub Profile
// Console.log alias
const l = (...args) => console.log(...args)
// Reject promise with custom error alias
const err = (rej, type) => rej(new Error(type))
// SetTimeout alias
const STO = (fn, ms) => setTimeout(fn, ms)
// new Promise alias
@afaur
afaur / LogUtil.js
Last active June 11, 2017 02:30
Make a replacement log function that doesn't require the parentheses.
// Get stdout off process as outPipe
const { stdout: outPipe } = process
// Import log and trace off of console
const { log, trace } = console
// Make a logRaw function
const logRaw = (...args) => outPipe.write(...args)
// Easy log fn for node
@afaur
afaur / aop.php
Last active June 7, 2017 18:13 — forked from bayleedev/aop.php
aspect oriented programming with traits in php
<?php
/**
* AOP Trait
* Used to created aop for your class.
*/
trait AOP {
public $filters = [];
public function applyFilter($NF) {
list($fnName, $fn) = $NF;
($this->unlessFilter($fnName)) && $this->initFilter($fnName);
@afaur
afaur / times.js
Created March 25, 2017 10:36
Add `Num(#).times` to Javascript (based on `#.times` in Ruby)
// Create a `Num` function that initializes a special object
// On the special object we define a property that acts like a function. This function
// calls a block/func the amount of times equal to the value passed in at the time of
// instance initialization.
var Num = function(num) {
var SpecialNumber = { value: num }
Object.defineProperty(SpecialNumber, 'times', {
get: function() {
var packages = [
'dbcli',
'meow',
'ruff',
]
function getInfo(name, cb) {
if (name === 'dbcli') {
setTimeout(() => {
cb({
@afaur
afaur / readBinary.js
Created February 5, 2017 23:55
Testing out binary reading and parsing in the browser
fetch('binary_file1.dat').then(function(response) {
return response.blob()
})
.then(function(blobData) {
var reader, header, level;
reader = new FileReader()
reader.addEventListener('loadend', function() {
// Each 16bit unsigned value is two bytes in size
// By asking for 0, 3 (pos 0-3) of the result we are taking 6 bytes.
header = new Uint16Array(reader.result, 0, 3)
@afaur
afaur / Mac OSX Sierra 10.12.1 Instructions.sh
Created January 13, 2017 00:27
Installing older .h files that are no longer in the latest Mac OSX SDK
# Go the temp directory on your machine
cd /tmp
# Download the 10.11 sdk from apple
wget http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_macOS_10.11_for_Xcode_8.2/Command_Line_Tools_macOS_10.11_for_Xcode_8.2.dmg
# (If you don't have wget copy the dmg to the `/tmp` folder)
# Mount the dmg
hdiutil attach Command_Line_Tools_macOS_10.11_for_Xcode_8.2.dmg
@afaur
afaur / ImageMagick 6.9.7-3 Homebrew Formula.md
Last active May 15, 2018 07:50 — forked from rochoa/ImageMagick 6.7.7-10 Homebrew Formula.md
Homebrew Formula for ImageMagick 6.9.7-3

Homebrew Formula patching old ImageMagick release 6.9.7-3

Install

$ brew install https://gist.githubusercontent.com/afaur/15fbb18b28e2140ec3fda8b098262e55/raw/b733366d08da64f87bc889eebf173f4e50e394bc/imagemagick.rb

Tested

// site: http://www.beaufortonline.com/building-and-construction-terms-dictionary/
// Get element with class '.nine'
var items = document.querySelector('.nine').getElementsByTagName('p');
// Find total amount of 'p' elements inside of tag with class '.nine'
var total = items.length;
// Collect terms and definitions
var terms = {}
marketing:
submit to electron
hacker news
reddit
electron weekly
javascript weekly
react weekly
product hunt
alternative to