Skip to content

Instantly share code, notes, and snippets.

View mcsf's full-sized avatar

Miguel Fonseca mcsf

View GitHub Profile
@mcsf
mcsf / gist:3623303
Created September 4, 2012 16:43
Simple e-mail notifications for Gmail. Requires Desktop Notifications and wget/curl.
#!/usr/bin/env python
# Limitations:
# - only the last sender will be shown for a given conversation with
# multiple new messages
# TODO
# - chmod for config file
# - config for every default value
@mcsf
mcsf / text-count.lisp
Created September 20, 2012 20:23
text-count.lisp
;; Constants
(defconstant *whitespace* '(#\space #\tab #\newline #\return))
(defconstant *separator* "EOF")
;; Predicates
(defun whitespace-p (char)
"Returns a given character if it is whitespace, NIL otherwise."
@mcsf
mcsf / gist:5481130
Last active December 16, 2015 18:50
[WordPress] Displays up to $length characters of the contents of the current post, taking care not to split words.
<?php
function mcsf_the_content( $length ) {
$content = get_the_content();
$content = apply_filters( 'the_content', $content );
$content = wp_filter_nohtml_kses( $content );
$extra = substr( $content, $length, $length + 20 );
$content = substr( $content, 0, $length );
$matches = array();
echo $content;
@mcsf
mcsf / gist:8293785
Created January 7, 2014 02:28
Infinite Scroll's allowed query variables by default
[allowed_vars] => Array
(
[0] => m
[1] => p
[2] => posts
[3] => w
[4] => cat
[5] => withcomments
[6] => withoutcomments
[7] => s
@mcsf
mcsf / underscore-functional.js
Created March 28, 2014 13:42
Functional mixins for Underscore
_.mixin({
flipAll: function(f) {
return function() {
var args = Array.prototype.slice.call(arguments).reverse();
return f.apply(this, args);
};
},
flip: function(f) {
return function() {
var args = Array.prototype.slice.call(arguments),
fun! run#Run()
if !exists("g:RunPath")
let g:RunPath = input("Run? ")
end
exe "!" . g:RunPath
endfun
nmap <F9> :call run#Run()<cr>
@mcsf
mcsf / backbone-autofetch.js
Created August 12, 2014 20:27
Autofetch in a Backbone Model/Collection with throttling; autopause if page not in view
Collection = Backbone.Collection.extend({
// ...
autofetch: function(interval, throttle) {
var maybeFetch = function() {
if (! document.hidden) { this.fetch(); }
}.bind(this);
this.fetch = _.throttle(this.fetch, throttle * 1000);
<?php
/**
* Includes a few useful predicates in the bootstrapped `infiniteScroll` JS object
* that is served along with the rest of the document upon initial page request.
*/
add_filter( 'infinite_scroll_js_settings', 'mcsf_extra_js_settings' );
function mcsf_extra_js_settings( $js_settings ) {
$js_settings['query_args']['extra'] = array(
'is_home' => is_home(),
@mcsf
mcsf / .gitconfig
Last active August 29, 2015 14:10
[core]
editor = vim
[push]
# do everyone a favor:
default = simple
#[merge]
#tool = vimdiff
@mcsf
mcsf / cartesian.js
Last active January 22, 2016 23:31
Cartesian product
import { flatten } from 'lodash'
const flatMap = (xs, f) => flatten(xs.map(f))
/**
* > cartesian([1, 2], [4, 5, 6], [7])
* [ [ 1, 4, 7 ],
* [ 1, 5, 7 ],
* [ 1, 6, 7 ],
* [ 2, 4, 7 ],
* [ 2, 5, 7 ],