Skip to content

Instantly share code, notes, and snippets.

View idettman's full-sized avatar

Isaac A. Dettman idettman

View GitHub Profile
@ngryman
ngryman / README.md
Last active January 16, 2023 14:07
intellij javascript live templates

intellij javascript live templates

Just a dump of handy live templates I use with IntelliJ. They should also work with WebStorm.

How to

  • Go to settings.
  • Search for live templates.
  • Under the javascript section you should be able to manage your templates.
# This is a really old post, in the comments (and stackoverflow too) you'll find better solutions.
def find(key, dictionary):
for k, v in dictionary.iteritems():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
elif isinstance(v, list):
@Raynos
Raynos / exploration.md
Last active August 18, 2022 22:31
Exploration of a TodoMVC app using FRP javascript techniques.

Implementing TodoFRP in JavaScript

FRP to me means building your app by transforming values over time, from the input to the current state to the display.

This implementation is based on a the [graphics][1] library and is heavily inspired by [Elm][2]

A full implementation of TodoFRP can be found [online at Raynos/graphics example server][3]

Moving away from MVC

@jcracknell
jcracknell / levenshtein.js
Last active December 17, 2015 00:11
Efficient Javascript implementation of Levenshtein distance.
// Compute the Levenshtein distance between `Array`-like sequences `a` and `b`; the minimum number of
// single-element insertions, deletions and substitutions necessary to transform `a` into `b`.
// Strict equality semantics are used by default to compare sequence elements; a function `equal` can
// optionally be provided to alter this behavior.
function levenshtein(a, b, equal) {
// `aii` and `bii` are used to track `ai - 1` and `bi - 1` more or less free of charge.
// `d0` and `d1` are used to store the 'previous' and 'current' rows respectively.
// `x`, `y` and `z` are used to permit the implementation of an optimized `min` using a ternary expression.
var ai, aii, ae, al, bi, bii, bl, d0, d1, dd, x, y, z;
if(a === b) return 0;
@roine
roine / helper.js
Last active December 17, 2015 10:49
web app helper
var helper = window.helper = {
/*
Boolean
*/
isiPad: navigator.userAgent.match(/iPad/i) != null,
isRetina: window.devicePixelRatio && window.devicePixelRatio > 1,
isOnline: navigator.onLine,
isWebAppMode: window.navigator.standalone || false,
landscape: function(){ return Math.abs(helper.orientation) === 90; },
portrait: function(){ return !helper.landscape() },
@DanAntFerrari
DanAntFerrari / meta_viewport.js
Created June 14, 2013 11:50
Create meta vieport an mobile tag by JS
var HandheldFriendlyTag=document.createElement('meta');
HandheldFriendlyTag.id="HandheldFriendly";
HandheldFriendlyTag.name = "HandheldFriendly";
HandheldFriendlyTag.content = "true";
document.getElementsByTagName('head')[0].appendChild(HandheldFriendlyTag);
var MobileOptimizedTag=document.createElement('meta');
MobileOptimizedTag.id="MobileOptimized";
MobileOptimizedTag.name = "MobileOptimized";
MobileOptimizedTag.content = "320";
document.getElementsByTagName('head')[0].appendChild(MobileOptimizedTag);
@Plou
Plou / projectName.local.plou
Created June 18, 2013 21:23
a virtual host example, Access-Control-Allow-Origin set to allow any request from foreign domains
## projectName
<VirtualHost *:80>
ServerName projectName.local.plou
CustomLog "/www/.logs/projectName.local.plou-access_log" combined
ErrorLog "/www/.logs/projectName.local.plou-error_log"
DocumentRoot "/www/projectName/"
Header set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, PUT, GET, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "Content-Type"
</VirtualHost>
function quicksort (array, left, right) {
var index, pivot, l, r, temp;
if (array.length > 1) {
left = typeof left === 'undefined' ? 0 : left;
right = typeof right === 'undefined' ? array.length - 1 : right;
// partition(array, left, right)
@mwcz
mwcz / jsdoc_AMD_module.md
Last active February 26, 2017 05:36
Michael Mathews (JSDoc founder) explains how @name works and how to document my IIFE-nested multiple-AMD module definitions (wow, that sounds cooooool).

#########

Me:

#########

It's not that I want to avoid those particular tags; I just want to generate the most documentation with the fewest number of tags. Lots of tags start impacting code readability.

Here's a better illustration of my use case. A few constructors are defined inside of an IIFE in order to keep them out of the global namespace. They are then exported with an AMD module definition at the bottom:

(function () {
@steveosoule
steveosoule / add-rules-stylesheets-with-javascript.js
Created July 8, 2013 22:12
Add Rules to Stylesheets with JavaScript
// Add Rules to Stylesheets with JavaScript
// http://davidwalsh.name/add-rules-stylesheets
/* Getting the Stylesheet
Which stylesheet you add the rules to is up to you. If you have a specific stylesheet in mind, you can add an ID to the LINK or STYLE element within your page HTML and get the CSSStyleSheet object by referencing the element's sheet property. The stylesheets can be found in the document.styleSheets object:*/
var sheets = document.styleSheets; // returns an Array-like StyleSheetList
/*
Returns: