Skip to content

Instantly share code, notes, and snippets.

View polarity's full-sized avatar
🌍
Working from home

Robert Agthe polarity

🌍
Working from home
View GitHub Profile

Discord

General server rules

  • No blank nicknames.
  • No inappropriate nicknames.
  • No sexually explicit nicknames.
  • No offensive nicknames.
  • No nicknames with unusual or unreadable Unicode.
  • No inappropriate profile pictures.
Verifying my Blockstack ID is secured with the address 1KNLvToa8S8Ga2jeen3PNAjdjmX1cWbcMx https://explorer.blockstack.org/address/1KNLvToa8S8Ga2jeen3PNAjdjmX1cWbcMx
@polarity
polarity / indentation.js
Last active August 29, 2015 14:08
Sometimes you have to secure a method with a condition. But you also get one more indentation space. Is it okay to use something like in the second case? less secure or safe maybe? just asking
// Whats Better?
// more indentation
function myFunction(data){
if(data){
// do some important stuff
data.parse()
}
}
@polarity
polarity / javascript.partial.markdown
Last active July 10, 2024 21:18
# Functional Programming Javascript: using Partials

Functional Programming Javascript: using Partials

Partials are basically functions that return functions with some already predefined arguments and need some arguments to be completed. Let's say you have a function with several arguments to be set, but you don't want to set the majority of arguments over and over again because you need it more than once.

# my useless function to write something to the dom
function writeSomethingToDom(element, content){
	element.append(content);
}

# use the function repeatedly 
@polarity
polarity / underscore.compose.markdown
Created March 19, 2014 10:26
Functional Programming Javascript: Composing with underscore

Functional Programming Javascript: Composing with underscore

From the underscore.js documentation :

Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).

So what compose() basically does is, glueing functions together and returning a new function. Thats a really functional approach i like. You dont deal with passing around data, instead you declare some functions into a new one and apply it to your content.

Lets say you have some "useful", small standalone functions:

//----Get all divs on page---------
/* jQuery */
$("div")
/* native equivalent */
document.getElementsByTagName("div")
//----Get all by CSS class---------
@polarity
polarity / .inputrc
Created April 18, 2013 13:52
This allows you to search through your history using the up and down arrows … i.e. type "cd /" and press the up arrow and you'll search through everything in your history that starts with "cd /". Create ~/.inputrc and fill it with this:
"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on
@polarity
polarity / detect.js
Created April 16, 2013 16:02
"Here are a few browser and operating system detection one liners that have served me well over the years." via http://nextmarvel.net/blog/2011/02/one-line-javascript-browser-detection/
//Browsers
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/
var IE7 = (document.all && !window.opera && window.XMLHttpRequest && navigator.userAgent.toString().toLowerCase().indexOf('trident/4.0') == -1) ? true : false;
var IE8 = (navigator.userAgent.toString().toLowerCase().indexOf('trident/4.0') != -1);
var IE9 = navigator.userAgent.toString().toLowerCase().indexOf("trident/5")>-1;
var IE10 = navigator.userAgent.toString().toLowerCase().indexOf("trident/6")>-1;
var SAFARI = (navigator.userAgent.toString().toLowerCase().indexOf("safari") != -1) && (navigator.userAgent.toString().toLowerCase().indexOf("chrome") == -1);
var FIREFOX = (navigator.userAgent.toString().toLowerCase().indexOf("firefox") != -1);
var CHROME = (navigator.userAgent.toString().toLowerCase().indexOf("chrome") != -1);
var MOBILE_SAFARI = ((navigator.userAgent.toString().toLowerCase().indexOf("iphone")!=-1) || (navigator.userAgent.toString().toLowerCase().indexOf("ipod")!=-1) || (navigator.userAgent.toString().toLowerCase().indexOf("
@polarity
polarity / index.js
Created February 17, 2013 18:41
voxel.js game
var createGame = require('voxel-engine')
function sphereWorld(x, y, z) {
// return the index of the material you want to show up
// 0 is air
if (x*x + y*y + z*z > 15*15) return 0
return 3
}
var game = createGame({
@polarity
polarity / gist:4375021
Last active December 10, 2015 03:28
How to read and write a cookie
// page one: set cookie after successful login
setCookie("myLogin", "Username or a different String", 2);
// page two: get cookie with this variable name
var cookie = readCookie("myLogin");
// redirect if theres no cookie with this variable
if (!cookie) {
// redirect to page one