This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Utils | |
{ | |
public static class Util | |
{ | |
public static string InBetween(string haystack, string afterThis, string beforeThis) | |
{ | |
return InBetween(haystack, afterThis, beforeThis, 1, 0); | |
} | |
public static string InBetween(string haystack, string afterThis, string beforeThis, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Utils | |
{ | |
public static class Util | |
{ | |
public static string UpperFirstChar(string s) | |
{ | |
if (s == null) return null; | |
if (s.Length == 1) return s.ToUpper(); | |
if (s.Length > 1) return char.ToUpper(s[0]) + s.Substring(1); | |
return s; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Utils | |
{ | |
public static class Util | |
{ | |
public static string GetFirstMatch(string pattern, string s, int index, bool removeDots = false) | |
{ | |
if (s == null) return null; | |
Regex regex = new Regex(pattern); | |
Match m = regex.Match(s); | |
while (m.Success) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?PHP | |
function generateToken($s) { | |
for ($i = 0; $i < 1000 + strlen($s) * 17; $i++) { | |
$s = hash_hmac('sha256', $s, 'Token #'.((7919+$i)/17).'static salt!'); | |
} | |
return $s; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array1 = [1,2,'a',3,'b',4,5] | |
const array2 = [1,2,'a',3,'b',4,5,6,'k'] | |
const checkIfArrayHasNValuesOfSameDataTypeCohesively = datatype => n => array => (array.reduce((acc, val) => ( | |
{passed: acc.passed || (acc.n = typeof val != datatype ? 0 : acc.n + 1) >= n, n: acc.n} | |
), {n: 0, passed: false})).passed; | |
const hasThreeNumbersCohesively = checkIfArrayHasNValuesOfSameDataTypeCohesively('number')(3); | |
console.log(hasThreeNumbersCohesively(array1)); // false | |
console.log(hasThreeNumbersCohesively(array2)); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array1 = [1,2,'a',3,'b',4,5] | |
const array2 = [1,2,'a',3,'b',4,5,6,'k'] | |
const checkIfArrayHasNValuesOfSameDataTypeCohesively = datatype => n => array => (array.reduce((acc, val) => { | |
if ((acc.n = typeof val != datatype ? 0 : acc.n + 1) >= n) acc.passed = true; | |
return acc; | |
}, {n: 0, passed: false})).passed; | |
console.log(checkIfArrayHasNValuesOfSameDataTypeCohesively('number')(3)(array1)); // false | |
console.log(checkIfArrayHasNValuesOfSameDataTypeCohesively('number')(3)(array2)); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array1 = [1,2,'a',3,'b',4,5] | |
let array2 = [1,2,'a',3,'b',4,5,6,'k'] | |
const checkIfArrayHasNValuesOfSameDataTypeCohesively = datatype => n => array => { | |
let _n = 0; | |
for (let i = 0; i < array.length; i++) { | |
if (typeof array[i] == datatype) { | |
if (++_n >= n) return true; | |
} | |
else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace PermutationOfPalindrome | |
{ | |
class Program | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace PermutationOfPalindrome | |
{ | |
class Program | |
{ |