Skip to content

Instantly share code, notes, and snippets.

View hsribei's full-sized avatar

Helder S Ribeiro hsribei

View GitHub Profile
#!/usr/bin/ruby
`cat ~/.bash_aliases | egrep '^alias' | sed 's/alias//'`.split("\n").each do |line|
parts = line.strip.split(/=/)
name, cmd = parts[0], parts[1].gsub(/('|")/,'')
file = '/home/%s/.config/fish/functions/%s.fish' % [`whoami`.strip, name]
content = [ 'function %s' % name, ' %s $argv;' % cmd, 'end' ].join("\n")
File.open(file, 'w+'){|io| io.write(content) }
end
@bartaz
bartaz / gist:1119041
Created August 1, 2011 21:22
Convert JavaScript number to string of 64bit double precision floating point representation (IEEE 754)
// Convert a JavaScript number to IEEE-754 Double Precision
// value represented as an array of 8 bytes (octets)
//
// http://cautionsingularityahead.blogspot.com/2010/04/javascript-and-ieee754-redux.html
function toIEEE754(v, ebits, fbits) {
var bias = (1 << (ebits - 1)) - 1;
// Compute sign, exponent, fraction
@mbostock
mbostock / .block
Last active July 8, 2023 20:00
SVG foreignObject Example
license: gpl-3.0
@mikeal
mikeal / gist:1840641
Created February 16, 2012 01:33
get a new/clean port with node.js
var portrange = 45032
function getPort (cb) {
var port = portrange
portrange += 1
var server = net.createServer()
server.listen(port, function (err) {
server.once('close', function () {
cb(port)
@mpereira
mpereira / gist:3072187
Created July 8, 2012 18:26
A little help to stop unconsciously checking distracting web sites.
alias focus="sudo sh -c \"echo '127.0.0.1 www.facebook.com twitter.com mail.google.com # aab6de513ab5de9359809f3cdb62d352' >> /etc/hosts\""
alias unfocus='sudo sed -i "" "/aab6de513ab5de9359809f3cdb62d352/d" /etc/hosts'
@ashblue
ashblue / nodejs-recursive-directory.js
Created October 19, 2012 05:06
NodeJS recursive directory listing without a module package
/**
* Goes through the given directory to return all files and folders recursively
* @author Ash Blue ash@blueashes.com
* @example getFilesRecursive('./folder/sub-folder');
* @requires Must include the file system module native to NodeJS, ex. var fs = require('fs');
* @param {string} folder Folder location to search through
* @returns {object} Nested tree of the found files
*/
// var fs = require('fs');
function getFilesRecursive (folder) {
@nelix
nelix / background.js
Created October 25, 2012 05:21
Chrome extension which reloads all unpacked extensions on opening of a url, for use with gruntjs's watch task.
/*
* Use with grunt-exec command: 'open -a "/Applications/Google Chrome.app" file://localhost/reload'
*/
chrome.webRequest.onBeforeRequest.addListener(hook, {urls: ['file://localhost/reload*']});
function hook(details) {
console.log('reloading all dev extensions');
chrome.management.getAll(function(extensions){
for(var i in extensions){
extension = extensions[i];
# Thanks to this post:
# http://blog.ikato.com/post/15675823000/how-to-install-consolas-font-on-mac-os-x
$ brew install cabextract
$ cd ~/Downloads
$ mkdir consolas
$ cd consolas
$ curl -O http://download.microsoft.com/download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26/PowerPointViewer.exe
$ cabextract PowerPointViewer.exe
$ cabextract ppviewer.cab
@fpoirier1
fpoirier1 / email-template.html
Created June 11, 2014 18:01
Render template on server with UnderscoreJS
<!-- private/email-template.html -->
<div>Welcome {{name}}</div>
@staltz
staltz / introrx.md
Last active April 18, 2024 15:33
The introduction to Reactive Programming you've been missing