Skip to content

Instantly share code, notes, and snippets.

@jmoz
jmoz / twitter_favouriter.py
Created August 1, 2013 21:55
Twitter API favouriter
from twitter import Twitter, OAuth, TwitterHTTPError
OAUTH_TOKEN = 'foo'
OAUTH_SECRET = 'bar'
CONSUMER_KEY = 'baz'
CONSUMER_SECRET = 'bat'
t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET))
@jmoz
jmoz / phpunit_chaining.php
Last active January 19, 2016 15:08
Phpunit mocking and chaining.
<?php
namespace Foo\Unit;
class Foo
{
public function foo($foo = true)
{
return $foo;
}
@jmoz
jmoz / README.md
Last active December 16, 2015 01:59 — forked from vanto/README.md

OEmbed Liquid Tag for Jekyll

This is a simple liquid tag that helps to easily embed images, videos or slides from OEmbed enabled providers. It uses Magnus Holm's great oembed gem which connects to the OEmbed endpoint of the link's provider and retrieves the HTML code to embed the content properly (i.e. an in-place YouTube player, Image tag for Flickr, in-place slideshare viewer etc.). By default it supports the following OEmbed providers (but can fallback to Embed.ly or OoEmbed for other providers):

  • Youtube
  • Flickr
  • Viddler
  • Qik
  • Revision3
  • Hulu
  • Vimeo
@jmoz
jmoz / python_import_this
Created April 7, 2013 12:32
Python import this
$ python
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
@jmoz
jmoz / python-linkedin.py
Last active December 14, 2015 04:39
An example of client code and XML response from LinkedIn's network_updates endpoint. The access tokens used have requested the rw_nus permission.
from linkedin import linkedin
import config
li = linkedin.LinkedIn(config.Linkedin.API_KEY, config.Linkedin.API_SECRET, 'http://foo.com')
"""the network_updates endpoint needs rw_nus permission, so do something like this during oauth flow:
li.request_token(['rw_nus', 'r_fullprofile'])
"""
@jmoz
jmoz / ratchet_redis.php
Created January 22, 2013 12:09
Ratchet and Predis-async. (React and Redis).
<?php
use RatchetApp\Pusher;
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$pusher = new Pusher();
$loop->addPeriodicTimer(10, array($pusher, 'timedCallback'));
@jmoz
jmoz / jquery_infinite_scroll.js
Last active December 11, 2015 07:28
jQuery infinite scroll.
<script type="text/javascript">
$(function(){
$('body > .container').infinitescroll({
navSelector : "div.pagination",
nextSelector : "div.pagination a:last",
itemSelector : "div.item",
bufferPx: 1000,
});
@jmoz
jmoz / twitter_pagination.html
Created January 18, 2013 17:36
Twitter bootstrap HTML with Pagination object.
<div class="pagination pagination-right">
<ul>
<li{% if not pagination.prev_page %} class="disabled"{% endif %}><a {% if pagination.prev_page %}href="{{ url_for('index', page=pagination.prev_page) }}"{% endif %}>Prev</a></li>
{% for page in pagination.pages %}
{% set url_paged = url_for('index', page=page) %}
{% set url_not_paged = url_for('index') %}
<li {% if page == pagination.current_page %}class="active"{% endif %}><a {% if page != pagination.current_page %}href="{% if page == 1 %}{{ url_not_paged }}{% else %}{{ url_paged }}{% endif %}"{% endif %}>{{ page }}</a></li>
{% endfor %}
<li {% if not pagination.next_page %}class="disabled"{% endif %}><a {% if pagination.next_page %}href="{{ url_for('index', page=pagination.next_page) }}"{% endif %}>Next</a></li>
</ul>
@app.route('/')
@app.route('/<int:page>')
def index(page=1):
# set up the pagination params, set count later
p = Pagination(per_page=10, current_page=page)
timeline = RedisTimeline.find_paginated(p)
# pass the pagination object to the view, so a list of links can be displayed
return render_template('index.html', timeline=timeline, pagination=p)
@jmoz
jmoz / pagination_tests.py
Created January 18, 2013 16:25
A unittest for Python Pagination class.
import unittest
from pagination import Pagination
class PaginationTest(unittest.TestCase):
def test_start(self):
p = Pagination(15, per_page=5, current_page=1)
self.assertEqual(0, p.start)
p.current_page = 2