Skip to content

Instantly share code, notes, and snippets.

@localpcguy
localpcguy / simple-hash.js
Created April 1, 2024 19:36 — forked from jlevy/simple-hash.js
Fast and simple insecure string hash for JavaScript
// These hashes are for algorithmic use cases, such as bucketing in hashtables, where security isn't
// needed and 32 or 64 bits is enough (that is, rare collisions are acceptable). These are way simpler
// than sha1 (and all its deps) or similar, and with a short, clean (base 36 alphanumeric) result.
// A simple, *insecure* 32-bit hash that's short, fast, and has no dependencies.
// Output is always 7 characters.
// Loosely based on the Java version; see
// https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript
const simpleHash = str => {
let hash = 0;
@localpcguy
localpcguy / .profile
Created September 27, 2019 17:55 — forked from bmhatfield/.profile
Automatic Git commit signing with GPG on OSX
# In order for gpg to find gpg-agent, gpg-agent must be running, and there must be an env
# variable pointing GPG to the gpg-agent socket. This little script, which must be sourced
# in your shell's init script (ie, .bash_profile, .zshrc, whatever), will either start
# gpg-agent or set up the GPG_AGENT_INFO variable if it's already running.
# Add the following to your shell init to set up gpg-agent automatically for every shell
if [ -f ~/.gnupg/.gpg-agent-info ] && [ -n "$(pgrep gpg-agent)" ]; then
source ~/.gnupg/.gpg-agent-info
export GPG_AGENT_INFO
else
@localpcguy
localpcguy / CamelCaseMacro.velocity
Created October 26, 2018 20:15 — forked from Pencroff/CamelCaseMacro.velocity
Transformation file name to CamelCase in IntelliJ IDEA file templates
## file name transformation
## file-name => FileName
## Sources:
## http://stackoverflow.com/questions/6998412/velocity-string-function
## http://stackoverflow.com/questions/21288687/using-velocity-split-to-split-a-string-into-an-array-doesnt-seem-to-work
## http://velocity.apache.org/engine/releases/velocity-1.7/apidocs/org/apache/velocity/util/StringUtils.html#split(java.lang.String, java.lang.String)
#set( $CamelCaseName = "" )
#set( $part = "" )
//<p class="name">hi {{name}}</p>
Handlebars.templates["hi"]=function(data) {
return "<p class=\"name\">hi "
+ escapeExpression(data['name'])
+ "</p>\n";
});
@localpcguy
localpcguy / p4merge4git.md
Created May 9, 2017 20:59 — forked from tony4d/p4merge4git.md
Setup p4merge as a visual diff and merge tool for git
@localpcguy
localpcguy / object-forin-forown.js
Created February 27, 2017 15:31 — forked from cowboy/object-forin-forown.js
JavaScript: Object#forIn and Object#forOwn
/*
* Object#forIn, Object#forOwn
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
Object.defineProperties(Object.prototype, {
forIn: {