Skip to content

Instantly share code, notes, and snippets.

View princejwesley's full-sized avatar
💻
Available for Hire

Prince John Wesley princejwesley

💻
Available for Hire
View GitHub Profile
@princejwesley
princejwesley / gulpfile.js
Last active August 29, 2015 14:26
Gulp configuration sample for ng-attr-hint plugin
var gulp = require('gulp');
var ngAttrHint = require('ng-attr-hint');
var gutil = require('gulp-util');
gulp.task('ng-attr-hint', function() {
ngAttrHint({ files: ['./*.html'] })
.then(function(res) {
res.forEach(function(row) {
//Use ngAttrHint.format(row) for default formatting
gutil.log("[", gutil.colors.bold.green(row.file), ":", gutil.colors.magenta(row.line),
@princejwesley
princejwesley / ng-attr-hint.png
Last active August 29, 2015 14:26
ng-attr-hint output
ng-attr-hint.png
@princejwesley
princejwesley / gulp-angular-module-task.js
Created November 23, 2015 13:07
Gulp pipe-able function for creating angular modules only when its not already created
var through = require('through2');
var moduleWrapper = through.obj(function (chunk, enc, cb) {
var content = chunk._contents.toString();
var newContent = content.replace(/angular\s*\.\s*module\s*\(\s*['"]([^'"]+)['"]\s*,\s*\[([^\]]*)\][^)]*\)/mg, function(match, mod, deps) {
// ignore ngHtml2Js templates module name
// if(mod === 'app.templates') { return match; }
return "((function () {\n try {\n return angular.module('" + mod + "');\n } catch (e) {\n return angular.module('" + mod + "', [" + deps + "]);\n }\n})())";
});
chunk._contents = new Buffer(newContent);
@princejwesley
princejwesley / query.ex
Last active October 7, 2020 17:24
Minimal LINQ like Query for elixir
defmodule Enum.Query.CompileError do
@moduledoc ~S"""
Raise compile time error while building query
"""
defexception [:message]
end
defmodule Enum.Query do
@moduledoc ~S"""
@princejwesley
princejwesley / ToggleDebug.elm
Last active May 27, 2016 02:23
[elm] Toggle on/off Debug.log
-- Toggle Debug.log
-- For non production use only
import Debug exposing(log)
-- (1) with |>
1 + 1 |> log "Addition" -- prints "Addition: 2" and returns 2
-- turn off logging
1 + 1 -- |> log "Addition"
@princejwesley
princejwesley / precision.js
Last active August 26, 2016 11:13
Numbers Precision
/*
three sgnificant figures for large numbers expressed using power of ten suffixes "k", "M" and "B". Ex: 12.3k, 1.45m, 534k
For sub 1000 and > 0 numbers, use 4 significant figures - ex: 12.34, 1.234, 123.4
For numbers above 10B, use scientific notation of the form 1.23x10^11
For numbers < 0.001, use scientific notation of the form 1.23x10^-5
For numbers in range 0.001 < n < 1.0, use 3 decimal places - ex: 0.123
*/
@princejwesley
princejwesley / await-babel-repl.js
Last active January 9, 2021 09:20
REPL with standalone await + babel transform
const repl = require('repl');
const babel = require('babel-core');
function preprocess(input) {
const awaitMatcher = /^(?:\s*(?:(?:let|var|const)\s)?\s*([^=]+)=\s*|^\s*)(await\s[\s\S]*)/;
const asyncWrapper = (code, binder) => {
let assign = binder ? `global.${binder} = ` : '';
return `(function(){ async function _wrap() { return ${assign}${code} } return _wrap();})()`;
};
@princejwesley
princejwesley / gcp-prefixes.js
Created April 20, 2018 18:38
Google storage platform: list only prefixes (directories) of given prefix(directory)
const Storage = require('@google-cloud/storage');
function getPrefixes(cred, bucketName, queryParams = {}) {
return new Promise((resolve, reject) => {
new Storage(cred)
.bucket(bucketName)
.request({
uri: '/o',
qs: {
delimiter: queryParams.delimiter || '/',