Skip to content

Instantly share code, notes, and snippets.

@dodolboks
dodolboks / contoh templates
Created January 21, 2012 06:47
contoh kustom templates brungut.com
{% extends "tema/retroika/base.html" %}
{% block extra_css %}
<link href="http://media.brungut.com/css/tema/retroika/layout.css" rel="stylesheet" type="text/css" />
{% if user.kustom_layout %}
<style>{{ user.css }}</style>
{% endif %}
{% endblock %}
{% block extra_js %}
@dodolboks
dodolboks / gist:5284171
Last active December 15, 2015 15:49
websocket like server in python with bottle + gevent-socket.io
from gevent import monkey; monkey.patch_all()
from bottle import request, Bottle, abort
from socketio.namespace import BaseNamespace
from socketio.mixins import RoomsMixin, BroadcastMixin
from socketio import socketio_manage
import redis
import json
from socketio.server import SocketIOServer
import os, re

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

import mongoengine
class MongoModelSerializer(serializers.ModelSerializer):
def get_default_fields(self):
cls = self.opts.model
opts = get_concrete_model(cls)
#pk_field = opts.pk
fields = []
fields += [getattr(opts, field) for field in opts._fields]
#fields += [field for field in opts.many_to_many if field.serialize]
@dodolboks
dodolboks / gist:8272467
Created January 5, 2014 19:08
example add extra data in Jquery File Upload - https://blueimp.github.io/jQuery-File-Upload/‎
$("#fileupload").fileupload({
dataType: 'json',
url:'/kelas/{{ kelas.id }}/new/image/',
add: function (e, data) {
no_img = 1
$("#btnSubmit").click(function () {
title = $("input#titleimg").val();
data.formData = {title:title, no_img:no_img};
data.submit();
no_img += 1

Spesifikasi API

Data Publisher

api_key = 'grvf1aS06XDvkf2kXC2RVEdaNhgcH2BujtcD42GltgQ'

api_secret = 'bb9b879e5aa4c6c3e495c070eb3442ef3bb392ee4140f44be7dff32c'

Register

"""
Example of setting up CORS with Bottle.py.
"""
from bottle import Bottle, request, response, run
app = Bottle()
@app.hook('after_request')
def enable_cors():
"""
@dodolboks
dodolboks / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# Example based on http://lukeplant.me.uk/blog/posts/djangos-cbvs-were-a-mistake/
# Not tested, just designed to give a general idea of the games CBVs let you play
from django.core.urlresolvers import reverse_lazy
from django.views.generic.edit import ProcessFormView
# Utilities for interacting with a user
class UserViewMixin(object):
_high_priority_user = None
@property
@dodolboks
dodolboks / titlefirst.py
Created December 19, 2015 18:20
Custom django template to replace title filters. this filter used in production on https://kelaskita.com Kelas Belajar Online
from django import template
register = template.Library()
@register.filter
def titlefirst(value):
import re
s = re.sub("(^|\s)(\S)", repl_func, value)
return s