Skip to content

Instantly share code, notes, and snippets.

@u0d7i
u0d7i / disable_vim_auto_visual_on_mouse.txt
Last active February 27, 2024 14:08
Disable vim automatic visual mode on mouse select
Disable vim automatic visual mode on mouse select
issue: :set mouse-=a
add to ~/.vimrc: set mouse-=a
my ~/.vimrc for preserving global defaults and only changing one option:
source $VIMRUNTIME/defaults.vim
set mouse-=a
@DmitrySoshnikov
DmitrySoshnikov / Recursive-descent-backtracking.js
Last active January 3, 2024 17:15
Recursive descent parser with simple backtracking
/**
* = Recursive descent parser =
*
* MIT Style License
* By Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*
* In this short lecture we'll cover the basic (non-predictive, backtracking)
* recursive descent parsing algorithm.
*
* Recursive descent is an LL parser: scan from left to right, doing
@sogko
sogko / app.js
Last active November 8, 2022 12:31
gulp + expressjs + nodemon + browser-sync
'use strict';
// simple express server
var express = require('express');
var app = express();
var router = express.Router();
app.use(express.static('public'));
app.get('/', function(req, res) {
res.sendfile('./public/index.html');
@kimmobrunfeldt
kimmobrunfeldt / node-exports-styles.js
Last active July 1, 2023 18:39
A few Node module export styles. 1 seems to be the most used and I prefer it
// Style 1
// Export all manually
// Good: Calling functions inside the module is convenient
// Bad: module.exports becomes verbose and it's tedious to add new functions
function a() {
b()
}
@danharper
danharper / background.js
Last active March 30, 2024 18:25
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
@mjackson
mjackson / color-conversion-algorithms.js
Last active April 14, 2024 08:46
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
@klovadis
klovadis / gist:5170485
Created March 15, 2013 15:03
A Lua script for Redis that allows you to set hash values based on a dictionary table
-- sets all fields for a hash from a dictionary
local hmset = function (key, dict)
if next(dict) == nil then return nil end
local bulk = {}
for k, v in pairs(dict) do
table.insert(bulk, k)
table.insert(bulk, v)
end
return redis.call('HMSET', key, unpack(bulk))
end
@johnpolacek
johnpolacek / gist:3827270
Last active January 20, 2023 15:46
Prevent FOUC
<!-- Prevent FOUC (flash of unstyled content) - http://johnpolacek.com/2012/10/03/help-prevent-fouc/ -->
<style type="text/css">
.no-fouc {display: none;}
</style>
<script type="text/javascript">
document.documentElement.className = 'no-fouc';
// add to document ready: $('.no-fouc').removeClass('no-fouc');
</script>
@creationix
creationix / chatServer.js
Created November 19, 2010 20:47
A simple TCP based chat server written in node.js
// Load the TCP Library
net = require('net');
// Keep track of the chat clients
var clients = [];
// Start a TCP Server
net.createServer(function (socket) {
// Identify this client