Skip to content

Instantly share code, notes, and snippets.

View agalazis's full-sized avatar
🌴
On vacation

Andreas Galazis agalazis

🌴
On vacation
View GitHub Profile
// Douglas Crockford's once
// Part 5: The End of All Things, Slide 39
// Once or throw exception
function once(func) {
return function () {
var f = func;
func = null;
return f.apply(this, arguments);
}
@bennadel
bennadel / average-age.js
Created December 24, 2015 19:25
The Best Way To Compute The Average Age Of Cat Owners In Functional Programming
var _ = require( "lodash" );
// Assume a collection that has:
// - age: Number
// - hasCat: Boolean
var people = require( "./people.json" );
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
@bsodmike
bsodmike / mongodb.md
Last active April 22, 2019 20:13
'Scaling 100GB of Data', posted on MongoDB

I managed to recover this post by checking Google's cached copy as it was randomly taken down; Enjoy!

Surpassing 100GB of data in your application requires you to have in-depth knowledge of how to operate and run MongoDB. MongoHQ recommends going through the 100GB Scaling Checklist as you grow. Watch the webinar recording on the subject for the full overview:

  • Identify your data behavior: Figure out how your data patterns and how they are working within your application. You will need to link your data to how your application accesses this data. Consider the simple queries and the more complex queries you will need to look up, like multi-range queries.
  • Refactor your schema to simplify queries
  • Remove data that does not fit MongoDB: remove “unrefactorable” data
  • Separate hot and cold data
  • Don’t lean on mongodump’: this disrupts RAM and c
@vodolaz095
vodolaz095 / install.sh
Last active January 31, 2021 10:00
Little script to help me installing Fedora 32 linux on my home PCs (comment lines you do not need)
#!/bin/sh
echo "Start SSHD service"
systemctl enable sshd
systemctl start sshd
echo "Remove junky programs i hate"
dnf -y remove clipit asunder gnomebaker lxmusic gnumeric osmo pidgin xpad
echo "Upgrade system"
@udomsak
udomsak / postman_fc29_install.sh
Created December 24, 2018 17:00
Install postman on Fedora core 29 - Dec 2018
#!/bin/bash
wget https://dl.pstmn.io/download/latest/linux64 -O postman-linux-x64.tar.gz
sudo tar xvzf postman-linux-x64.tar.gz -C /opt
sudo ln -s /opt/Postman/Postman /usr/bin/postman
cat << EOF > ~/.local/share/applications/postman2.desktop
[Desktop Entry]
Name=Postman
GenericName=API Client
@dai-shi
dai-shi / benchmark-startswith.js
Created February 14, 2013 03:51
benchmark of String.startsWith equivalents in Node.js
var Benchmark = require('benchmark');
Benchmark.prototype.setup = function() {
a = ["test"];
for (var i = 0; i < 10000; i++) {
a.push("some other stuff");
}
s = a.join();
re1 = new RegExp("^test");
re2 = new RegExp("^not there");
};
@Sinkler
Sinkler / settings.py
Created July 22, 2019 15:23
Show SQL traceback in Django
if os.environ.get('DEBUG_SQL') or os.environ.get('DEBUG_SQL_TRACEBACK'):
LOGGING['loggers']['django.db.backends'] = {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
}
if os.environ.get('DEBUG_SQL_TRACEBACK'):
import traceback
import logging
@sevcsik
sevcsik / nodejs-angularjs-common-modules.md
Last active February 15, 2022 09:38
Sharing modules between NodeJS and AngularJS

They say that one of the pros of NodeJS is that you use the same language on the back-end and the front-end, so it's easy to share code between them. This sounds great in theory, but in practice the synchronous dependency handling in NodeJS works completely different than any client-side frameworks (which are asynchronous).

Usually that means that you end up copy-pasting your code between your NodeJS sources and your client-side sources, or you use some tool like Browserify, which is brilliant, but they add an extra step in the build process and most likely will conflict with the dependency handling of the framework of your choice (like AnularJS DI). I couldn't look in the mirror if I would call that code sharing.

Fortunately, with a couple of lines of boilerplate code, you can write a module which works in NodeJS and AngularJS as well without any modification.

No globals in the front-end, and dependencies will work. The isNode and isAngular va

@jas-
jas- / class.stream.php
Last active June 2, 2022 18:22
PHP stream handler w/ support for multiple files over PUT
<?php
/**
* stream - Handle raw input stream
*
* LICENSE: This source file is subject to version 3.01 of the GPL license
* that is available through the world-wide-web at the following URI:
* http://www.gnu.org/licenses/gpl.html. If you did not receive a copy of
* the GPL License and are unable to obtain it through the web, please
*
@sumardi
sumardi / gist:5559896
Created May 11, 2013 12:56
Subdirectory checkouts with Git sparse-checkout
# New repository
mkdir <repo> && cd <repo>
git init
git remote add –f <name> <url>
git config core.sparsecheckout true
echo some/dir/ >> .git/info/sparse-checkout
echo another/sub/tree >> .git/info/sparse-checkout
git pull <remote> <branch>
# Existing repository