Skip to content

Instantly share code, notes, and snippets.

View marcellodesales's full-sized avatar

Marcello DeSales marcellodesales

View GitHub Profile
@un33k
un33k / sed cheatsheet
Created August 22, 2011 13:28
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@dbodyas
dbodyas / decimal.js
Created February 12, 2012 15:30
JavaScript Get Unicode char as decimal
/*
Sometimes, unicode symbols that have to be inserted in an HTML page should be escaped.
For example, everybody know, that’s “&” should be escaped as “&”, ” ” as “ ” and so on.
But what, if you should insert symbol, that you never used before. So you don’t know how it should be present or escaped.
Code below, helps you to get valid decimal unicode for appropriate symbol.
*/
function getCharAsDecimalUTF8(char){
var getUTF8 = escape(char);
console.log("&#" + parseInt(getUTF8.substring(getUTF8.match(/\%u/) !== null ? 2 : 1), 16) + ";");
}
@EwanDawson
EwanDawson / regex-capture.groovy
Created April 17, 2012 16:09
Idiomatic regex group capturing in Groovy
// Using Matcher object returned by =~ operator
matcher = "Hello world v1.01" =~ /.* v(\S*)/
if (matcher.matches()) version = matcher[0][1]
assert version == "1.01"
// We can make this a little tidier using the 'with' method
version = ("Hello world v1.01" =~ /.* v(\S*)/).with { matches() ? it[0][1] : null }
assert version == "1.01"
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active April 2, 2024 15:59
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@andsens
andsens / benchmark-ec2-boottime.sh
Created October 1, 2012 19:02
Starts a single instance and measures the time until SSH connectivity
#!/bin/bash -e
# These need to be set.
#export EC2_HOME="/path/to/ec2-api-tools"
#export AWS_ACCESS_KEY='XXXXXXXXXXXXXXXXXXXX'
#export AWS_SECRET_KEY='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
#export PATH="$PATH:${EC2_HOME}/bin"
ami_id='ami-123abc12'
availability_zone='eu-west-1a'
keypair="johndoe@example.com"
@dergachev
dergachev / README.md
Created October 10, 2012 16:49
Vagrant tutorial

Vagrant Setup

This tutorial guides you through creating your first Vagrant project.

We start with a generic Ubuntu VM, and use the Chef provisioning tool to:

  • install packages for vim, git
  • create user accounts, as specified in included JSON config files
  • install specified user dotfiles (.bashrc, .vimrc, etc) from a git repository

Afterwards, we'll see how easy it is to package our newly provisioned VM

@mbostock
mbostock / .block
Last active April 28, 2024 23:11
Force-Directed Graph
license: gpl-3.0
height: 600
redirect: https://observablehq.com/@d3/d3-force-directed-graph
@nateware
nateware / s3update.py
Last active February 1, 2023 22:07
Check local files vs what's on S3, and upload any that have changed.
#!/usr/bin/env python
# Compare a file on S3 to see if we have the latest version
# If not, upload it and invalidate CloudFront
import fnmatch
import os
import boto
import pprint
import re
@wumpz
wumpz / gist:5846559
Created June 23, 2013 21:12
list authors of a git repository including commit count and email
git shortlog -e -s -n
@bewest
bewest / .gist.markdown
Last active December 20, 2015 16:09
use node restify to handle mime body uploads

Use node to handle file upload

Edit
# https://gist.github.com/6159923.git
gist=git@gist.github.com:6159923.git

git clone $gist blip_upload
# OR
git remote add origin $gist