Skip to content

Instantly share code, notes, and snippets.

@jedfoster
jedfoster / javascript.js
Created October 12, 2012 19:47
Textarea selection and caret manipulation with Javascript
HTMLTextAreaElement.prototype.getCaretPosition = function () { //return the caret position of the textarea
return this.selectionStart;
};
HTMLTextAreaElement.prototype.setCaretPosition = function (position) { //change the caret position of the textarea
this.selectionStart = position;
this.selectionEnd = position;
this.focus();
};
HTMLTextAreaElement.prototype.hasSelection = function () { //if the textarea has selection then return true
if (this.selectionStart == this.selectionEnd) {
@zenorocha
zenorocha / README.md
Last active May 28, 2024 08:23
A template for Github READMEs (Markdown) + Sublime Snippet

Project Name

TODO: Write a project description

Installation

TODO: Describe the installation process

Usage

@JT5D
JT5D / _.md
Created February 13, 2013 12:31
LeapMotion Three.js Visualizer
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active July 2, 2024 00:02
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@elithrar
elithrar / authserver.go
Last active June 30, 2021 07:12
HTTP Basic Auth example in Go (based on http://stackoverflow.com/a/21937924/556573 + bespoke middleware implementation)
package main
import (
"encoding/base64"
"github.com/gorilla/mux"
"net/http"
"strings"
)
func main() {
@timetocode
timetocode / interp-sample.js
Created April 23, 2014 22:43
Entity interpolation
/* Entity Interpolation
this code occurs within the draw loop for an entity
this.x and this.y represent the most recently received server position of
the entity -- though i don't ever intend to use it for drawing
when an update is received (roughly every 50ms in my particular game) this.x and this.y get
pushed into previousState.x and previousState.y
i also continue sloppily onwards to previousPreviousState.x, but I've removed that code
@bellbind
bellbind / earth.html
Last active January 24, 2022 01:09
[threejs][html5] Put current location on sphere with geolocation API
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script
src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
></script>
<script
src="https://rawgit.com/mrdoob/three.js/master/examples/js/controls/TrackballControls.js"
></script>
@gaearon
gaearon / combining.js
Created June 3, 2015 18:03
Combining Stateless Stores
// ------------
// counterStore.js
// ------------
import {
INCREMENT_COUNTER,
DECREMENT_COUNTER
} from '../constants/ActionTypes';
const initialState = { counter: 0 };
@telekosmos
telekosmos / uniq.js
Last active November 15, 2022 17:13
Remove duplicates from js array (ES5/ES6)
var uniqueArray = function(arrArg) {
return arrArg.filter(function(elem, pos,arr) {
return arr.indexOf(elem) == pos;
});
};
var uniqEs6 = (arrArg) => {
return arrArg.filter((elem, pos, arr) => {
return arr.indexOf(elem) == pos;
});
@leesei
leesei / cLogger.js
Created August 20, 2015 16:14
Logger to Browser console (with colors)
// http://charlesbking.com/power_of_es6/#/21
//create a logger facade
class Logger {
//constructor
constructor (type = "Info") {
this.type = type;
}
//static methods
static create(type) {