Skip to content

Instantly share code, notes, and snippets.

View MrBenJ's full-sized avatar
🤓
Hey are you gonna eat that

Ben Junya MrBenJ

🤓
Hey are you gonna eat that
View GitHub Profile
@MrBenJ
MrBenJ / promises.js
Created January 27, 2020 15:58
Promise Example
// Required on in a Node.js environment
const fetch = require('isomorphic-fetch');
async function getInfoFromServer() {
// WITHOUT ASYNC/AWAIT
// fetch('https://deckofcardsapi.com/api/deck/new/draw/?count=1')
// .then(response => {
// return response.json();
// }).then(json => {
// console.log('I drew the card, the ' + json.cards[0].value + ' of ' + json.cards[0].suit );
### Keybase proof
I hereby claim:
* I am mrbenj on github.
* I am bouqsbjunya (https://keybase.io/bouqsbjunya) on keybase.
* I have a public key ASD7EulbPY4MMFXmJKZxwx8TS7Wx59HPh6rs4RGaZTjFNgo
To claim this, I am signing this object:
@MrBenJ
MrBenJ / example.js
Last active October 2, 2018 00:41
A real world example of how JS Promises work (A+ Specification)
import { getJSON } from './promise_example';
function init() {
getJSON('my-url.com').then( data => {
// data, the first param of resolve(), contains
// the response data from the XHR request
console.log(data);
}).catch( error => {
// oh no, something went wrong!
// error is the first param of reject()
@MrBenJ
MrBenJ / gist:2599bfdb4fb87631f7c9d6ebb5b976d2
Created February 7, 2018 19:07
"TRON" game code challenge for live coding interview
/*
Libs included:
underscore lodash chai sinon sinon-chai mocha async request q bluebird jsdom
*/
function makeMove(move, currentPosition) {
let newPosition = [...currentPosition];
switch(move) {
### Keybase proof
I hereby claim:
* I am mrbenj on github.
* I am mrbenj (https://keybase.io/mrbenj) on keybase.
* I have a public key ASDEXUOG5iULUVhLq520Vvz9wAbEklEw_UTTOcbUmVW4IAo
To claim this, I am signing this object:
@MrBenJ
MrBenJ / app.js
Created October 23, 2015 22:32
Algorithm to register all handlebars partials at once on an express server.
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var hbs = require('hbs');
@MrBenJ
MrBenJ / hbshelper.js
Created October 23, 2015 00:28
A Handlebars Helper that compares 2 things.
/**
* USAGE:
*
* {{#compare 'firstArgument' '===' 'secondArgument'}}
* <h1>I get rendered if the condition above is true!</h1>
* {{/compare}}
*
* **/
hbs.registerHelper('compare', function(left, operation, right, options) {
@MrBenJ
MrBenJ / ViewHolder_Pattern_Adapter.java
Last active August 31, 2015 00:10
Recycling Views using convertView == null and ViewHolder
// This is the @Override getView() portion of the Adapter class - recycles views in order to create a faster
// and much more efficient UI. Boosts framerates from 15 FPS to 50 FPS due to savvy memory allocation.
private LayoutInflater mInflater;
private List<SomeObject> mList;
// Constructor for Adapter object
public nameOfAdapter(Context context, List<SomeObject> myListOfObjects) {
mInflater = LayoutInflater.from(context);
mList = myListOfObjects;
@MrBenJ
MrBenJ / Prescale_Bitmaps
Created October 15, 2014 02:57
Pre-Scale Bitmaps
originalImage = Bitmap.createScaledBitmap(
originalImage // Bitmap to resize
view.getWidth(), // new width
view.getHeight(), // new height
true); // Enable bilinear filtering