Skip to content

Instantly share code, notes, and snippets.

@frangio
frangio / gist:846950
Created February 28, 2011 04:49
a jquery method to get the position of an object relative to the viewport (doesn't work that well sometimes, because of merged margins and such)
(function($) {
$.fn.viewportPosition = function() {
var a = this, b = a.offset().top - $(window).scrollTop(), c = a.offset().left - $(window).scrollLeft();
return {top: b, left: c};
};
})(jQuery);
@frangio
frangio / gist:985684
Created May 22, 2011 17:22
Vim - Don't create swap files for files in the Dropbox folder (useful for folders shared with Windows people)
autocmd BufNewFile,BufRead *
\ if expand('%:~') =~ '^\~/Dropbox' |
\ set noswapfile |
\ else |
\ set swapfile |
\ endif
@frangio
frangio / check_gmail.rb
Created May 24, 2011 00:17
Checks Gmail and shows a Growl notification (using growlnotify) with unread count.
#! /usr/bin/env ruby
begin
response = %x{ curl -u username:password --silent "https://mail.google.com/mail/feed/atom" }
fullcount = response.match(/<fullcount>(\d+)<\/fullcount>/)[1].to_i
message = fullcount > 0 ? fullcount.to_s + " new message(s)." : "No new messages."
rescue
message = "There was an error."
ensure
%x{ growlnotify "#{message}" -m "" --image "icon.png" }
@frangio
frangio / ruby-polyfill.css
Created April 12, 2012 19:17
Ruby Polyfill
/* Simplified version of http://www.useragentman.com/blog/2010/10/29/cross-browser-html5-ruby-annotations-using-css/
for use with Modernizr.load() */
ruby {
display: inline-table;
text-align: center;
border-collapse: collapse;
border: none;
vertical-align: middle;
border-bottom: solid 0.75em transparent;
@frangio
frangio / datauri.sh
Last active December 13, 2015 18:38
Converts file passed as argument to Data URI representation.
#!/usr/bin/env sh
echo "data:$(file -b --mime-type "$1");base64,$(base64 "$1")"
@frangio
frangio / lambda.pl
Last active August 29, 2015 14:24
This is an interpreter for the pure untyped lambda calculus.
% This is an interpreter for the pure untyped lambda calculus.
% We represent lambda terms using De Bruijn indices.
term(var(I)) :- integer(I).
term(abs(M)) :- term(M).
term(app(M, N)) :- term(M), term(N).
% Lambda abstractions are the only values.
@frangio
frangio / i3-empty-ws
Created August 14, 2015 06:13
Lua script to switch to next empty workspace in i3wm. Depends on i3ipc-lua.
#!/usr/bin/env lua
i3ipc = require 'i3ipc'
conn = i3ipc.Connection()
tree = conn:get_tree()
ws = {}
for _, w in pairs(tree:workspaces()) do
if w.focused then
var TelegramBot = require('node-telegram-bot-api');
var token = 'TOKEN';
var bot = new TelegramBot(token, {polling: true});
bot.getMe().then(function (me) {
console.log('%s on', me.username);
});
bot.on('text', function (msg) {
@frangio
frangio / dmenu_run
Last active March 24, 2016 23:43
Enhanced `dmenu_run`.
#!/bin/sh
set -o errexit
is_graphical() {
desktop=/usr/share/applications/"$1".desktop
[ -f "$desktop" ] && ! grep -Fq Terminal=true "$desktop" \
|| ldd "$(which "$1")" | grep -Fq libX11
}
@frangio
frangio / ltn12-posix.lua
Last active October 8, 2015 20:53
LTN12 wrappers for POSIX read and write.
local unistd = require('posix.unistd')
local ltn12 = require('ltn12')
local _M = {}
-- creates a source from a file descriptor
function _M.source(fd, err)
if fd then
return function ()
local chunk = unistd.read(fd, ltn12.BLOCKSIZE) -- [TODO] stat(fd).st_blksize?