Skip to content

Instantly share code, notes, and snippets.

View cantecim's full-sized avatar
✌️
work wonders

Can Tecim cantecim

✌️
work wonders
View GitHub Profile

Recursively copy a directory (using cp, tar or rsync)

Original Source: http://snipplr.com/view/26670/

Reformatted for improved readability and personal reference.

How does one make a recursive, identical copy of /source/ into /target/?

I suppose you want to do that for archiving or duplicating something and want to preserve "everything". That includes permissions, ownership, filetypes, timestamps etc.

@cantecim
cantecim / random.md
Created October 9, 2023 15:12 — forked from joepie91/random.md
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@cantecim
cantecim / foxitcl-mobilePolyForm.js
Last active January 16, 2016 16:28 — forked from premiumFrye/pf-mobilePolyForm.js
A directive for making Android behave a bit more like iOS when filling out forms using the ionic framework. Directive will automatically advance cursor to next field when user taps return, and if the next field is a select input, automatically pop open options. Additionally, this directive solves an issue where angularjs won't update ng-model an…
angular.module('foxitcl-mobilePolyform', [])
.directive('mobileFormPolyfill', function($timeout, $parse) {
return {
compile: function(tElement, tAttrs) {
tAttrs.inputs = [];
tAttrs.keydownFns = [];
var formElements = tElement[0].elements,
k = -1;
Object.keys(formElements).forEach(function(elm) {
@cantecim
cantecim / node-and-npm-in-30-seconds.sh
Created July 30, 2015 02:09 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.com/install.sh | sh