Skip to content

Instantly share code, notes, and snippets.

View AkyunaAkish's full-sized avatar

Akyuna Akish AkyunaAkish

  • Amazon
  • remote
View GitHub Profile
@AkyunaAkish
AkyunaAkish / flatten.js
Created September 2, 2016 15:55
CitrusByte - Experienced Frontend Engineer Position
const flatten = (nestedArr) => {
const flattened = [].concat.apply([], nestedArr);
for(let i = 0; i < flattened.length; i++) {
if(flattened[i] instanceof Array) {
return (flatten(flattened))
}
}
return flattened;
@AkyunaAkish
AkyunaAkish / checkAllInvoices.js
Last active January 14, 2017 00:13
Bulk SQL SELECT WHERE IN statement using javascript, nodeJS, sequelize, lodash
// invoices is an array of objects
function checkAllInvoices(invoices) {
return new Promise((resolve, reject) => {
let valueString = '';
_.each(invoices, (invoice, i) => {
valueString += `'${invoice.Id}'${i < invoices.length-1 ? ',' : ''}`;
});
let selectStatement = `SELECT * FROM user_mgmt.stripe_invoices WHERE sf_invoice_id IN (${valueString});`;
@AkyunaAkish
AkyunaAkish / retrieveAllStripeCustomers.js
Created January 14, 2017 00:03
Retrieving all Stripe customers recursively in NodeJS
let _ = require('lodash');
let stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
const next100 = (starting_after) => {
return stripe.customers.list({
limit: 100,
starting_after: starting_after
})
.then((customers) => {
return customers;
$http.post('http://localhost:3000/users/signin', {
email: email,
password: password
})
.then(function(res) {
console.log(res.data);
})
.catch(function(err) {
console.log(err);
});
@AkyunaAkish
AkyunaAkish / customDataBindingBetweenControllers.js
Last active January 22, 2017 22:11
Custom data binding between multiple controllers in Angular 1.5x
// Explanation: Sharing a value between multiple controllers can be done by using a service to create a custom data-bind.
// 1. You have a service that has a variable that will be shared between multiple controllers.
// 2. In the service you have getter and setter methods in order for your controllers to both receive the shared value and change the shared value.
// 3. You inject that service into all of the controllers you want to share the value between.
// 4. At the top of your controllers that will be using the shared value, immediately set a $scope variable to the return value of the getter method for the shared value that is available through the service.
// 5. Create a $scope.$watch statement that returns the value of the getter method for the shared value.
// 6. The $scope.$watch method will run whenever a $scope variable in one of your controllers change it's value or whenever a $scope function is called.
// 7. If the $scope.$watch detects a change in the return value of your getter method for the sha
@AkyunaAkish
AkyunaAkish / $q.js
Last active November 17, 2022 03:41
$q angular 1.5x promises
function hasSession(data) {
var deferred = $q.defer();
if (data.user && data.token) {
deferred.resolve(true);
} else {
deferred.reject(false);
}
return deferred.promise;
@AkyunaAkish
AkyunaAkish / Promise.all.js
Last active January 27, 2017 20:37
Multiple http requests at once, if a promise is rejected it won't stop the Promise.all and will return both the successes and the rejections in the finishedPromises. NodeJS Stripe Lodash Bluebird
let _ = require('lodash');
let stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
let Promise = require('bluebird');
function bulkChargeInvoices(chargeObjects) {
return new Promise((resolve, reject) => {
let promiseArray = [];
_.each(chargeObjects, (chargeObj) => {
promiseArray.push(stripe.charges.create(chargeObj.charge));
(function (angular) {
'use strict';
angular
.module('myApp', ['moment-picker'])
.directive('datetimeCalendar', function() {
return {
restrict: 'EA',
scope: {
asString: '=?',
asMoment: '=?',
// Original Query Which Works:
let dynamicQuery = `SELECT
s.name AS "Service"
${serviceFields}
${serviceComponentFields}
${locationAField}
${locationZField}
${governingContractField}
FROM salesforce.Service__c s
let dynamicQuery = `SELECT
s.name AS "Service"
,b.name as account_name
${serviceFields}
${serviceComponentFields}
${locationAField}
${locationZField}
${governingContractField}
FROM salesforce.Service__c s
${joinString}