Skip to content

Instantly share code, notes, and snippets.

View forivall's full-sized avatar
🕴️
levitating

Emily Marigold Klassen forivall

🕴️
levitating
View GitHub Profile
@creationix
creationix / superhack.js
Created November 23, 2010 01:09
A probably evil hack to get working super in any function.
// Add a handy super call for all objects
MyBaseClass.prototype.super = function () {
var parent = this.__proto__.__proto__;
var caller = arguments.callee.caller;
var fn;
if (caller.prototype === this.__proto__) {
fn = parent.constructor;
} else {
// This is probably quite slow, but it doesn't seem to affect
// performance too much in real tests.
@andyhd
andyhd / maybe-monad.js
Created January 16, 2012 01:02
Maybe monad in Javascript
function maybe(value) {
var obj = null;
function isEmpty() { return value === undefined || value === null }
function nonEmpty() { return !isEmpty() }
obj = {
map: function (f) { return isEmpty() ? obj : maybe(f(value)) },
getOrElse: function (n) { return isEmpty() ? n : value },
isEmpty: isEmpty,
nonEmpty: nonEmpty
}
@emanuelez
emanuelez / git_speed.md
Last active March 17, 2024 19:03
Git Speed

How Fast is Git?

The web is full of benchmarks showing the supernatural speed of Git even with very big repositories, but unfortunately they use the wrong variable. Size is not important, but the number of files in the repository really is!

Why is that? Well, that's because Git works in a very different way compared to Synergy. You don't have to checkout a file in order to edit it; Git will do that for you automatically. But at what price?

The price is that for every Git operation that requires to know which files changed (git status, git commmit, etc etc) an lstat() call will be executed for every single file

Wow! So how does that perform on a fairly large repository? Let's find out! For this example I will use an example project, which has 19384 files in 1326 folders.

@dalcib
dalcib / ngGrid.js
Created May 7, 2012 20:18
Angular Grid
//////////////////////////////////////
/// Grid Directive to Angular 1.0.0rc7
//////////////////////////////////////
// To use:
// <script>
// var app = angular.module('myapp', ['ngGrid']);
// var Ctrl = function($scope) { $scope.todo = [...] }
// </script>
// <div ng-app="myapp">
@leostratus
leostratus / webkit-pseudo-elements.md
Created September 21, 2012 01:44
Webkit Pseudo-Element Selectors (Shadow DOM Elements)

An ongoing project to catalogue all of these sneaky, hidden, bleeding edge selectors as I prepare my JSConf EU 2012 talk.

Everything is broken up by tag, but within each the selectors aren't particularly ordered.

I have not tested/verified all of these. Have I missed some or got it wrong? Let me know. - A

A friendly reminder that you may need to set this property on your target/selected element to get the styling results you want:

-webkit-appearance:none;

@datagrok
datagrok / git-branch-simplify.md
Last active April 16, 2024 17:26
How to simplify the graph produced by git log --graph

Ideas for improvements to git log --graph

I will maybe someday get around to dusting off my C and making these changes myself unless someone else does it first.

Make the graph for --topo-order less wiggly

Imagine a long-running development branch periodically merges from master. The git log --graph --all --topo-order is not as simple as it could be, as of git version 1.7.10.4.

It doesn't seem like a big deal in this example, but when you're trying to follow the history trails in ASCII and you've got several different branches displayed at once, it gets difficult quickly.

@bag-man
bag-man / cpu.js
Last active March 29, 2024 12:01
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores
generateUniqueID = () ->
_p8 = (s) ->
p = (Math.random().toString(16)+"000000000").substr(2,8)
if s then "-" + p.substr(0,4) + "-" + p.substr(4,4) else p
_p8() + _p8(true) + _p8(true) + _p8()
@natchiketa
natchiketa / yo-completion.sh
Last active May 25, 2018 20:47
Bash completion for Yeoman generators
# Bash completion for Yeoman generators - tested in Ubuntu, OS X and Windows (using Git bash)
function _yo_generator_complete_() {
# local node_modules if present
local local_modules=$(if [ -d node_modules ]; then echo "node_modules:"; fi)
# node_modules in /usr/local/lib if present
local usr_local_modules=$(if [ -d /usr/local/lib/node_modules ]; then echo "/usr/local/lib/node_modules:"; fi)
# node_modules in user's Roaming/npm (Windows) if present
local win_roam_modules=$(if [ -d $(which yo)/../node_modules ]; then echo "$(which yo)/../node_modules:"; fi)
# concat and also add $NODE_PATH
local node_dirs="${local_modules}${usr_local_modules}${win_roam_modules}${NODE_PATH}"
@joshkunz
joshkunz / vlcwrap.c
Last active December 22, 2015 03:29
Wrapper that will close VLC on OSX with a SIGKILL when it receives a SIGINT (useful if you want to terminate it from the command-line with Control-C).
/* Build, (with your favorite compiler) run:
* cc -o vlcwrap vlcwrap.c */
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define VLC_BIN "/Applications/VLC.app/Contents/MacOS/VLC"