Skip to content

Instantly share code, notes, and snippets.

View daviferreira's full-sized avatar

Davi Ferreira daviferreira

View GitHub Profile
@daviferreira
daviferreira / smooth-scrolling.coffee
Created March 31, 2012 23:46
Smooth scrolling for anchor '#' links using jQuery and CoffeeScript
# based on http://www.paulund.co.uk/smooth-scroll-to-internal-links-with-jquery
$ ->
$('a[href^="#"]').on 'click.smoothscroll', (e) ->
e.preventDefault()
target = @hash
$target = $(target)
@daviferreira
daviferreira / compiler.js
Last active April 18, 2017 21:42
Mocha compiler for es6 + react components with css require statements
'use strict';
var babel = require('babel-core');
var fs = require('fs');
// borrowed from https://github.com/babel/babel-jest/blob/master/index.js
require.extensions['.jsx'] = function (module, filename) {
var src = fs.readFileSync(filename, 'utf8');
// Allow the stage to be configured by an environment
// variable, but use Babel's default stage (2) if
@daviferreira
daviferreira / admin_filters.html
Created July 8, 2011 16:28
How to change django's list_filter order
{% load i18n %}
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
<ul>
<li {% if choices.0.selected %}class="selected"{% endif %}><a href="?"><strong>All</strong></a></li>
{% for choice in choices|dictsort:"display" %}
{% if choice.query_string != "?" %}
<li {% if choice.selected %}class="selected"{% endif %}><a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
{% endif %}
{% endfor %}
</ul>
export CLICOLOR=1
export LSCOLORS=gxfxcxdxBxxxxxxxxxxxxx
# Colors from http://wiki.archlinux.org/index.php/Color_Bash_Prompt
NO_COLOR='\e[0m' #disable any colors
# regular colors
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
@daviferreira
daviferreira / gist:5576447
Created May 14, 2013 14:40
console crossbrowser
/**
* Protect window.console method calls, e.g. console is not defined on IE
* unless dev tools are open, and IE doesn't define console.debug
*/
(function () {
if (!window.console) {
window.console = {};
}
// union of Chrome, FF, IE, and Safari console methods
var functionCall = function () {},
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
location @prerender {
set $prerender 0;
if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|developers\.google\.com") {
set $prerender 1;
}
if ($args ~ "_escaped_fragment_|prerender=1") {
set $prerender 1;
}
if ($http_user_agent ~ "Prerender") {
set $prerender 0;
@daviferreira
daviferreira / html5-css3.md
Created February 13, 2012 16:34
HTML5/CSS3 workshop links
@daviferreira
daviferreira / gem-virtualenv.sh
Created January 29, 2012 12:38
Gems and virtualenvs
# add this to your virtualenv activate script
export GEM_HOME="$VIRTUAL_ENV/gems"
export GEM_PATH=""
@daviferreira
daviferreira / article.css
Created January 24, 2012 17:56
Basic CSS for articles.
body { color: #222; font: normal normal 400 100%/1.5em georgia,serif; margin: 3em auto; width: 40em }
a:link { color: #3366CC }
a:visited { color: #224488 }
blockquote,ol,p,ul { display: block; margin: 0 0 1.5em }
blockquote { border-left: solid .1em #E4E4E4; color: #919191; padding: 0 1.5em 0 1.4em }
code { font: normal normal 87.5%/1.71428571em monospace,sans-serif }
img { display: block; margin: 1.5em auto }
pre { display: block; font: normal normal 87.5%/1.71428571em monospace,sans-serif; margin: 1.71428571em }
h1,h2,h3,h4,h5,h6 { font-weight: 400 }
h1 { font-size: 225%; line-height: 1.3334em; margin: 0 0 .1666em }