Skip to content

Instantly share code, notes, and snippets.

View b2whats's full-sized avatar
🎯
Focusing

Akimov Vladimir b2whats

🎯
Focusing
View GitHub Profile
@juandopazo
juandopazo / gist:1182244
Created August 30, 2011 22:14
JavaScript without logical operators or loops
function _if(truthy, then) {
[then, function () {}][+!truthy]();
}
function ifElse(truthy, then, _else) {
[then, _else][+!truthy]();
}
function and(a, b) {
return !!((!!a + !!b) >> 1);
@mooz
mooz / check-cnf.js
Created December 30, 2011 08:05
CNF (Conjunctive Normal Form)
var cnfs = [
// (a || c) && (c || d || b)
new Term(
Term.AND,
new Term(
Term.OR,
new Term(Term.LITERAL, "a"),
new Term(Term.LITERAL, "c")
),
new Term(
@munro
munro / auto_restart_node.js
Created January 11, 2012 18:43
Auto Restart Node
// Auto restart server on file changes
(function () {
var fs = require('fs'),
original = require.extensions['.js'];
function exitOnChange(filename) {
fs.watchFile(filename, function (curr, prev) {
if (curr.mtime !== prev.mtime) {
process.exit();
}
@ydaniv
ydaniv / mozGetMatchedCSSRules.js
Created July 2, 2012 12:32
A Gecko only polyfill for Webkit's window.getMatchedCSSRules
// polyfill window.getMatchedCSSRules() in FireFox 6+
if ( typeof window.getMatchedCSSRules !== 'function' ) {
var ELEMENT_RE = /[\w-]+/g,
ID_RE = /#[\w-]+/g,
CLASS_RE = /\.[\w-]+/g,
ATTR_RE = /\[[^\]]+\]/g,
// :not() pseudo-class does not add to specificity, but its content does as if it was outside it
PSEUDO_CLASSES_RE = /\:(?!not)[\w-]+(\(.*\))?/g,
PSEUDO_ELEMENTS_RE = /\:\:?(after|before|first-letter|first-line|selection)/g;
// convert an array-like object to array
@joaocunha
joaocunha / How To Hide The Select Arrow On Firefox.md
Last active December 10, 2023 13:05
How to hide <select> dropdown's arrow in Firefox when using "-moz-appearance: none;".

This is no longer a bug. I'm keeping the gist for historical reasons, as it helped to get it fixed. Make sure to read the notes by the end of the post.

How to remove hide the select arrow in Firefox using -moz-appearance:none;

TL;DR (or, the fix)

  1. Set -moz-appearance to none. This will "reset" the styling of the element;
  2. Set text-indent to 0.01px. This will "push" the text a tiny bit[1] to the right;
// polyfill window.getMatchedCSSRules() in FireFox 6+
if ( typeof window.getMatchedCSSRules !== 'function' ) {
var ELEMENT_RE = /[\w-]+/g,
ID_RE = /#[\w-]+/g,
CLASS_RE = /\.[\w-]+/g,
ATTR_RE = /\[[^\]]+\]/g,
// :not() pseudo-class does not add to specificity, but its content does as if it was outside it
PSEUDO_CLASSES_RE = /\:(?!not)[\w-]+(\(.*\))?/g,
PSEUDO_ELEMENTS_RE = /\:\:?(after|before|first-letter|first-line|selection)/g;
// convert an array-like object to array
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@denji
denji / nginx-tuning.md
Last active May 3, 2024 03:57
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@andytlr
andytlr / _description.md
Last active August 1, 2023 08:02
Convert SVG <polyline> to <path> so they can be animated with D3 etc.

Convert SVG polyline to path

Replace all instances of <polyline with <path and points=" with d="M.

 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1000px" height="1000px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
-<polyline fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" points="100.712,141.534 582.904,227.835 425.37,478.521
+
Rx.Observable.prototype.pauseAndResume = function (subject) {
var source = this;
return Observable.create(function (observer) {
var q = [], previous = true;
var subscription =
source.combineLatest(
subject.distinctUntilChanged(),
function (data, shouldFire) {