Skip to content

Instantly share code, notes, and snippets.

View alfasin's full-sized avatar
🖖
He bag production, he got walrus gumboot

Nir Alfasi alfasin

🖖
He bag production, he got walrus gumboot
View GitHub Profile
@alfasin
alfasin / better-nodejs-require-paths.md
Last active January 7, 2020 21:30 — forked from branneman/better-nodejs-require-paths.md
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

@alfasin
alfasin / stringify.js
Created January 3, 2020 15:31 — forked from zmmbreeze/stringify.js
json stringify can deal with circular reference
// http://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json/11616993#11616993
var o = {};
o.o = o;
var cache = [];
JSON.stringify(o, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
@alfasin
alfasin / xor.py
Created October 24, 2018 02:56 — forked from revolunet/xor.py
Simple python XOR encrypt/decrypt
#
# NB : this is not secure
# from http://code.activestate.com/recipes/266586-simple-xor-keyword-encryption/
# added base64 encoding for simple querystring :)
#
def xor_crypt_string(data, key='awesomepassword', encode=False, decode=False):
from itertools import izip, cycle
import base64
if decode:
@alfasin
alfasin / uniq.js
Created June 1, 2018 22:38 — forked from telekosmos/uniq.js
Remove duplicates from js array (ES5/ES6)
var uniqueArray = function(arrArg) {
return arrArg.filter(function(elem, pos,arr) {
return arr.indexOf(elem) == pos;
});
};
var uniqEs6 = (arrArg) => {
return arrArg.filter((elem, pos, arr) => {
return arr.indexOf(elem) == pos;
});
@alfasin
alfasin / hashcat_macos.sh
Created April 21, 2018 04:18 — forked from chadmayfield/hashcat_macos.sh
Install Hashcat on macOS
#!/bin/bash
git clone https://github.com/hashcat/hashcat.git
mkdir -p hashcat/deps
git clone https://github.com/KhronosGroup/OpenCL-Headers.git hashcat/deps/OpenCL
cd hashcat/ && make
./hashcat --version
./hashcat -b -D 1,2
./example0.sh
@alfasin
alfasin / troubleshooting-with-jcmd.md
Last active August 29, 2015 14:27 — forked from noahlz/troubleshooting-with-jcmd.md
Troubleshooting Production JVMs with jcmd

Troubleshooting Production JVMs with jcmd

jcmd is a powerful new tool introduced in Java 7. Along with jstack and jps, it should be in your go-to tool for solving production problems on the JVM. (Come to think of it, with this tool you don't really need jps anymore)

Here's an example session with jcmd:

$ ssh wopr.qa.corp.local
$ jcmd -l
34739 sun.tools.jcmd.JCmd -l
@alfasin
alfasin / osx-setup.md
Last active August 29, 2015 14:14 — forked from zenorocha/.hyper.js

Setup Mac OS X

I'm in a hospital in Spain and my MacBook was stolen.

Hospital Commit

Now I bought a new one and need to configure it. I have an external hard drive that backup everything using Time Machine, but I don't want all the crap I had in the old one.

1. Run Software Update