Skip to content

Instantly share code, notes, and snippets.

View rabbishuki's full-sized avatar

Rabbi Shuki Gur rabbishuki

View GitHub Profile
@rabbishuki
rabbishuki / DataFactory.js
Created November 21, 2017 13:29
Upload a file with angular 1.5
// This service connects to our REST API
app.factory("Data", function ($http) {
var serviceBase = 'https://shekel.click/api/v1.2/';
var obj = {};
obj.file = function (q, file, fileName) {
var fd = new FormData();
fd.append('fileToUpload', file);
fd.append('fn', fileName);
fd.append('submit', 'ok');
@rabbishuki
rabbishuki / DataFactory.js
Created November 21, 2017 13:29
Upload a file with angular 1.5
// This service connects to our REST API
app.factory("Data", function ($http) {
var serviceBase = 'https://shekel.click/api/v1.2/';
var obj = {};
obj.file = function (q, file, fileName) {
var fd = new FormData();
fd.append('fileToUpload', file);
fd.append('fn', fileName);
fd.append('submit', 'ok');
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"lib": [
"es2017"
]
},
"include": [
"src/**/*"
@rabbishuki
rabbishuki / negativeNumberConfigPhase.js
Last active December 31, 2017 11:53
An AngularJS Decorator to format negative numbers with the currency filter.
angular.module('app')
.config(function ($provide) {
$provide.decorator('$locale', function ($delegate) {
if ($delegate.id == 'en-us') {
$delegate.NUMBER_FORMATS.PATTERNS[1].negPre = '-\u00A4';
$delegate.NUMBER_FORMATS.PATTERNS[1].negSuf = '';
}
return $delegate;
});
});
@rabbishuki
rabbishuki / negativeNumberFilter.js
Last active December 31, 2017 12:03
An AngularJS filter to format negative numbers with the currency filter.
app.filter('customCurrency', function ($filter) {
return function(amount, currencySymbol){
var currency = $filter('currency');
if(amount.charAt(0) === "-"){
return currency(amount, currencySymbol)
.replace("(", "-")
.replace(")", "");
}
@rabbishuki
rabbishuki / negativeNumberRunPhase.js
Last active December 31, 2017 12:08
An AngularJS Decorator to format negative numbers with the currency filter.
angular.module('app')
.run(function ($locale) {
var currencyPatterns = $locale.NUMBER_FORMATS.PATTERNS[1];
patterns.negPre = '-\u00a4';
patterns.negSuf = '';
});
@rabbishuki
rabbishuki / login.js
Last active January 5, 2018 09:34
Login from admin as a different user.
// If we have a token, try to login.
if (window.name) {
$.post("/login", {
token: window.name
});
}
/*
* The function to be called when clicking on a username from the Admin Panel.
* The second parameter of `window.open` is the new window's name.
sendToOtherNodeService = (url, bodyReq, timeout, callback) => {
try {
request({
url: url,
method: 'POST',
json: true,
body: bodyReq,
timeout: timeOut,
}, (error, response, body) => {
if (error != null) {