Skip to content

Instantly share code, notes, and snippets.

View service-now-custom-code.js
var _get;
window.SN = {
  get: function(scriptInclude, name, obj, cb) {
    return _get(scriptInclude, name, obj, cb, true);
  },
  getPlane: function(scriptInclude, name, obj, cb) {
    return _get(scriptInclude, name, obj, cb);
  }
};
View reduce.js
var arr = [1, 2, 3, 4, 5];
var sum = arr.reduce(function(pv, cv){
return cv + pv;
});
View custom-fonts.css
@font-face {
font-family: 'Guild Wars 2';
src: url('inc/fonts/GuildWars2.eot');
src: url('inc/fonts/GuildWars2.eot?#iefix') format('embedded-opentype'),
url('inc/fonts/GuildWars2.woff') format('woff'),
url('inc/fonts/GuildWars2.ttf') format('truetype'),
url('inc/fonts/GuildWars2.svg#GuildWars2Regular') format('svg');
font-weight: normal;
font-style: normal;
}
View toType.js
// toType better typeof
var toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}
toType({a: 4}); //"object"
toType([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
@DesignFront
DesignFront / detect-files-in-folder.go
Created Mar 4, 2021
goland: detect files in folder
View detect-files-in-folder.go
func getFilesInPath(rootPath string, fileType string) ([]FileObj, error) {
var files []FileObj
err := filepath.Walk(rootPath, func(path string, info os.FileInfo, err error) error {
// read file
if err != nil {
fmt.Print(err)
}
subStr := strings.Replace(path, "testdata/", "", -1)
@DesignFront
DesignFront / split-string-by-capital-letters.js
Last active Mar 4, 2021
Split string by capital/numbers
View split-string-by-capital-letters.js
value.replace(/(?!^)([A-Z]|\d+)/g, " $1");
View detect-dark-mode.js
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// dark mode
}
// to watch for changes:
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
console.log(`changed to ${e.matches ? "dark" : "light"} mode`)
});
View regex-destructuring.js
const [, year, month, day] = /^(\d\d\d\d)-(\d\d)-(\d\d)$/.exec('2999-12-31');
View fibonacci.js
// get the fib number:
function fib(n) {
let arr = [0,1,1];
for (let i = 3; i <= n; i++) {
arr.push(arr[i-2] + arr[i-1])
}
return arr[n]
}
View mongo.js
// Find (not equal to):
db.getCollection('Task').find({type: {$ne: 1}})
db.getCollection('documents').find({'pages.zones.regex': {$exists: true, $ne: ''}})
// Detect non empty strings
db.getCollection('DocumentDefinition').find({'pages.zones.regex': /(.|\s)*\S(.|\s)*/})