Skip to content

Instantly share code, notes, and snippets.

View codeimpossible's full-sized avatar
🍕
P I Z Z A

Jared Barboza codeimpossible

🍕
P I Z Z A
View GitHub Profile
@codeimpossible
codeimpossible / README.md
Created February 2, 2017 07:27
Looping inside promises

Promise Loops

I was building a CLI for GitHub code search which was using promises pretty heavily as the control flow of the application. It worked well enough in the beginning because the network library was promise based. However I wanted to add a feature where you could query the JSON returned by the GitHub API using json-query. This required that the user enter a REPL-type interaction, where they can enter a command and see the output, rinse and repeat until they have the data they want.

The problem is that all of the I/O in node is non-blocking. This means that all the libraries i looked at to capture user input from the command line were all either prommise based, or used node style method(data, callback) invocations. This ruled out my first option: using a while loop inside a promise to repeat the REPL until the user entered 'done'. If I did this I'd end up firing hundreds or thousands of calls to readline (the library I ended up using) to gather user i

@codeimpossible
codeimpossible / Program.cs
Last active January 9, 2017 18:06
Example of determining dependency injection based on interface attribute.
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Collections;
using System.Reflection;
using System.Threading.Tasks;
namespace ConsoleApp1
{
# needs to be run in Package Manager Console
# i made this multiple lines for readability,
# you might need to compact it to one to run it
Get-Project -All | ForEach-Object {
Write-Host "";
Write-Host $_.ProjectName;
Write-Host "------------";
Get-Package -ProjectName $_.ProjectName -Filter <PACKAGE_NAME> | ForEach-Object {
Write-Host ($_.Id, $_.Version) -Separator " "
}
@codeimpossible
codeimpossible / 1-hoisting.js
Last active August 29, 2015 14:23
Variable hoisting
var variable = "global";
function doSomething() {
console.log(variable);
var variable = 'local';
console.log(variable);
}
doSomething();
@codeimpossible
codeimpossible / blog-post-importer.es6
Created June 29, 2015 17:09
Abstract Factory, with self-registration!
let subclasses = {};
export default class BlogPostImporter {
constructor(body) {
for(var p in body) {
if(body.hasOwnProperty(p)) {
this[p] = body[p];
}
}
}
@codeimpossible
codeimpossible / pod-pub.ps1
Created February 7, 2015 13:18
Script to automate our podcast publishing
Param (
[Parameter(Mandatory=$True)]
[string]$url
)
# this assumes you have youtube-dl installed
# choco install youtube-dl
# this also assumes you have ffmpeg installed
# choco install ffmpeg
@codeimpossible
codeimpossible / JamesBond.cs
Created October 28, 2014 02:52
JamesBond - a quick and dirty lesson in reflection, invocation and generally mucking about with an objects private vars
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
using System.Reflection;
using System.Linq.Expressions;
namespace MISix {
public class ReflectedResult<T> {
# vim:ft=zsh ts=2 sw=2 sts=2
#
# Based on agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
#
@codeimpossible
codeimpossible / directions.md
Last active August 29, 2015 14:01
compiling ragel with js support on mac osx

Prerequisites

  • Node.js (0.10.9 or higher with npm)
  • Make sure you have gcc/g++ 4.6 (4.7 is too strict to build ragel-js)
  • Make sure you have autoconf and automake (brew install automake)
  • Make sure you have the official ragel (brew install ragel)

Clone the gcc patched version of ragel-js

$ git clone https://github.com/codeimpossible/ragel-js