Skip to content

Instantly share code, notes, and snippets.

@dodolboks
dodolboks / sse.nim
Created October 16, 2023 09:56 — forked from ingoogni/sse.nim
Experimenting with Server Sent Events in Nim
import asyncdispatch, asynchttpserver, asyncnet, nativesockets, net
import logging, oids, strformat, strutils, tables, times
#import sse_db
type SSEClient = object
fs: FutureStream[string]
clientClosed: int
req: Request
@dodolboks
dodolboks / finetune_llama_v2.py
Created July 19, 2023 08:29 — forked from younesbelkada/finetune_llama_v2.py
Fine tune Llama v2 models on Guanaco Dataset
# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@dodolboks
dodolboks / paddedzoom.py
Created July 9, 2023 07:46 — forked from i-namekawa/paddedzoom.py
zoom in/out an image (numpy array) while keeping the original shape.
import cv2
def paddedzoom(img, zoomfactor=0.8):
'''
Zoom in/out an image while keeping the input image shape.
i.e., zero pad when factor<1, clip out when factor>1.
there is another version below (paddedzoom2)
'''
@dodolboks
dodolboks / vncstart.sh
Last active November 2, 2018 07:14 — forked from ParkNoBreak/ini.txt
vncserver daemon
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 3 4 5
# Default-Stop: 0 6
### END INIT INFO
PATH="$PATH:/usr/X11R6/bin/"
# 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 / 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 of setting up CORS with Bottle.py.
"""
from bottle import Bottle, request, response, run
app = Bottle()
@app.hook('after_request')
def enable_cors():
"""
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]

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