Skip to content

Instantly share code, notes, and snippets.

View legomushroom's full-sized avatar
🇺🇦
stop russizm

Oleg Solomko legomushroom

🇺🇦
stop russizm
View GitHub Profile
replace-in-selector($what, $with = '')
/{replace($what, $with , selector())}
{block}
root-selector()
+replace-in-selector('^(\S+).*', '$1')
{block}
.foo
.bar
@juanbrujo
juanbrujo / README.md
Last active August 29, 2015 14:23
createElement JavaScript function

#createElement(element,attribute,inner);

use:

createElement("tag","[attr:val][attr:val]",[element1,"some text",element2,element3,"or some text again :)"]);

basic:

@chrillo
chrillo / star.js
Created November 23, 2011 14:07
Draw a star in html canvas
/*
takes the x,y coordinates, the number of spikes, the inner and the outer radius of the spikes
*/
function drawStar(ctx,cx,cy,spikes,r0,r1){
var rot=Math.PI/2*3,x=cx,y=cy,step=Math.PI/spikes
ctx.strokeSyle="#000";
ctx.beginPath();
@developit
developit / _readme.md
Last active February 3, 2017 15:01
Like linkState(), but for Refs.

Simple, unobtrusive add-on to support String refs in Preact, without needing to pull in preact-compat.

Option 1: Add-on

Calling linkRef(componentInstance, refName) returns a "ref proxy" function, which sets this.refs[refName] when called.

import { h, Component } from 'preact';
import linkRef from './linked-ref';
@eklimcz-zz
eklimcz-zz / touchEventWireup
Created September 25, 2012 16:52
Cross browser touch event wireup
function inferInputModel() {
if (window.navigator.msPointerEnabled) {
return 'pointer';
} else if (window.ontouchstart !== undefined) {
return 'touch';
} else {
return 'unknown';
}
}
@dburger
dburger / gist:1008320
Created June 4, 2011 20:26
Javascript Array Binary Heap
/*
array implementation of a binary heap, example usage:
// can optionally provide a comparison function, a function for a max
// heap is the default if no comparison function is provided
var bh = binaryHeap();
bh.push(5);
bh.push(34);
bh.push(16);
var max = bh.pop(); // 34
@nongio-zz
nongio-zz / node-term-tools.md
Last active November 13, 2017 17:23
nodejs terminal UI tools

nodejs terminal UI tools

Inquirer A collection of common interactive command line user interfaces. Used by yeoman

terminal-menu used in rvagg/workshopper learnyounode...

cli-color used in rvagg/workshopper learnyounode...

blessed A curses-like library for node.js.

@dsingleton
dsingleton / function-bind.js
Created October 25, 2011 11:10
Polyfill for Function.prototype.bind
Function.prototype.bind=Function.prototype.bind||function(b){if(typeof this!=="function"){throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");}var a=Array.prototype.slice,f=a.call(arguments,1),e=this,c=function(){},d=function(){return e.apply(this instanceof c?this:b||window,f.concat(a.call(arguments)));};c.prototype=this.prototype;d.prototype=new c();return d;};
@Ugarz
Ugarz / mobileAndTabletcheck.txt
Created December 10, 2015 13:06
Check if your device if mobile or tablet in Javascript
window.mobileAndTabletcheck = function() {
var check = false;
(function(a) {
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) ||
if (window.mobileAndTabletcheck == true)
// Have some complicated non-React widgets that manipulate DOM?
// Do they manage a list of DOM elements? Here's how to wrap it
// into a React component so you can "constantly rerender" it.
// A dumb non-react widget that manually manage some DOM node that
// represent a list of items
function NonReactWidget(node) {
this.node = node;
}