Skip to content

Instantly share code, notes, and snippets.

View DesignFront's full-sized avatar

Lynk DesignFront

View GitHub Profile
@DesignFront
DesignFront / service-now-custom-code.js
Created March 4, 2021 10:08
service now custom code
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);
  }
};
var arr = [1, 2, 3, 4, 5];
var sum = arr.reduce(function(pv, cv){
return cv + pv;
});
@DesignFront
DesignFront / custom-fonts.css
Created March 4, 2021 10:04
custom font faces
@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;
}
@DesignFront
DesignFront / toType.js
Created March 4, 2021 09:55
better typeof
// 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 March 4, 2021 09:52
goland: detect files in folder
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 March 4, 2021 10:18
Split string by capital/numbers
value.replace(/(?!^)([A-Z]|\d+)/g, " $1");
@DesignFront
DesignFront / detect-dark-mode.js
Last active September 12, 2021 20:04
Detect Darkmode
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`)
});
@DesignFront
DesignFront / regex-destructuring.js
Created February 5, 2020 18:25
Regex destructuring
const [, year, month, day] = /^(\d\d\d\d)-(\d\d)-(\d\d)$/.exec('2999-12-31');
@DesignFront
DesignFront / fibonacci.js
Last active March 4, 2021 10:18
Fibonacci
// 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]
}
@DesignFront
DesignFront / mongo.js
Created February 5, 2020 18:18
Mongo queries
// 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)*/})