Skip to content

Instantly share code, notes, and snippets.

View Narshe1412's full-sized avatar
📚
On my way to something great!

Manuel Narshe1412

📚
On my way to something great!
View GitHub Profile
@Narshe1412
Narshe1412 / RoundOrDefault.ts
Created February 17, 2020 12:51
TypeScript round function with a default return value if the object provided is not defined or not a number
/**
* Given an object with a property, it tests if the property is a number and returns the round of that
* Otherwise returns the value provided by defaultValue, or null
* @param obj The object that contains the property to test
* @param prop The property that will be tested
* @param decimalsToRound The number of decimals to round to
* @param defaultValue The default value provided if it cannot complete the transaction
*/
export const roundOrDefault = (obj: any, prop: string, decimalsToRound: number, defaultValue = null) => {
if (!obj) {
@Narshe1412
Narshe1412 / url_reset.py
Created September 5, 2019 08:17
Urls for django password reset
from django.conf.urls import url
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.views import password_reset, password_reset_done, password_reset_confirm, password_reset_complete
urlpatterns = [
url(r'^$', password_reset, {'post_reset_redirect' : reverse_lazy('password_reset_done')}, name="password_reset"),
url(r'^done/$', password_reset_done, name="password_reset_done"),
url(r'^(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', password_reset_confirm, {'post_reset_confirm': reverse_lazy('password_reset_complete')}, name="password_reset_confirm"),
url(r'^complete$', password_reset_complete, name="password_reset_complete"),
]
@Narshe1412
Narshe1412 / class.with.spreadsheet.js
Last active June 6, 2019 09:37
SpreadJS: Implement Alt+Down key for List Validator Dropdowns
const commandManager = workbook.commandManager();
commandManager.register('showListDown', () => openDropdown(sheet, workbook));
commandManager.setShortcutKey('showListDown', GC.Spread.Commands.Key.down, false, false, true);
@Narshe1412
Narshe1412 / getValidatorFromArray.js
Created June 6, 2019 09:31
SpreadJS: Create List Validator from Array including empty option
export const getListValidatorFromArray = (spread: GC.Spread.Sheets.Workbook, data: any[]) => {
// saving validation list values in a hidden sheet
spread.addSheet(spread.getSheetCount());
const sheet = spread.getSheet(spread.getSheetCount() - 1);
sheet.visible(false);
for (let i = 0; i < data.length; i++) {
sheet.setValue(i, 0, data[i]);
}
// create validator based on the values
const dv = GC.Spread.Sheets.DataValidation.createFormulaListValidator(
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using StackExchange.Redis;
using WebApp;
namespace ClassLib.CacheExtension
@Narshe1412
Narshe1412 / tasks.json
Created April 5, 2017 11:40 — forked from felixfbecker/tasks.json
VS Code Javac & JUnit tasks.json
/*
Example for quick Java compilation and unit tests in VS Code.
Works well with simple BlueJ projects.
Hit Ctrl+Shift+B to compile currently open file with javac.
Hit Ctrl+Shift+T to test currently open test class.
See red wiggles for compilation errors / failed assertions or click exclamation mark in the status bar.
Uses a few workarounds for individual commands per task and filename without extension.
This is written for Windows but it should be easy to adopt for Linux and Mac.
*/
{
@Narshe1412
Narshe1412 / Zipline: Build a JavaScript Calculator.markdown
Created June 29, 2016 03:02
Zipline: Build a JavaScript Calculator
var Person = function(firstAndLast) {
//this.fullName = firstAndLast;
var fullName = firstAndLast;
var splitName = fullName.split(" ");
var first = splitName[0];
var last = splitName[1];
this.getFirstName = function (){
//return first;
return fullName.split(" ")[0];
@Narshe1412
Narshe1412 / Binary Agent.js
Created December 17, 2015 20:13
http://www.freecodecamp.com/narshe1412 's solution for Bonfire: Binary Agents
function binaryAgent(str) {
var parsedString = str.split(" ");
for (i=0; i<parsedString.length; i++){
parsedString[i] = String.fromCharCode(parseInt(parsedString[i],2));
}
str = parsedString.join("");
return str;
}
@Narshe1412
Narshe1412 / Steamroller.js
Created December 17, 2015 19:41
http://www.freecodecamp.com/narshe1412 's solution for Bonfire:Steamroller
function steamroller(arr) {
// I'm a steamroller, baby
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? steamroller(toFlatten) : toFlatten); //ternary
}, []);
/*
Uses the same concat flatten example on the MDN, but with recursion to further flatten
ex:
var flattened = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {