Skip to content

Instantly share code, notes, and snippets.

View level09's full-sized avatar
🌴
Always on vacation

Nidal Alhariri level09

🌴
Always on vacation
View GitHub Profile
@level09
level09 / shorturl.py
Created October 21, 2014 09:52
Short ID Generator
'''
Short URL Generator
===================
Python implementation for generating Tiny URL- and bit.ly-like URLs.
A bit-shuffling approach is used to avoid generating consecutive, predictable
URLs. However, the algorithm is deterministic and will guarantee that no
collisions will occur.
{
"loc": "",
"youliked": false,
"title": "",
"deleted": false,
"text": "Nature",
"created_at": "2015-08-02 20:28:42",
"views": 0,
"media_thumb": "https://hostname/static/files/videos/2015/08/02/wToYREIrwhtnDdZtpgVQVRJjhIKvje.jpg",
"order": 101,
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 24320 1048 ? Ss May04 10:53 /sbin/init
root 2 0.0 0.0 0 0 ? S May04 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S May04 111:37 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< May04 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? S May04 0:00 [kworker/u:0]
root 7 0.0 0.0 0 0 ? S< May04 0:00 [kworker/u:0H]
root 8 0.0 0.0 0 0 ? S May04 0:00 [migration/0]
root 9 0.0 0.0 0 0 ? S May04 0:00 [rcu_bh]
root 10 0.0 0.0 0 0 ? S May04 107:26 [rcu_sched]
@level09
level09 / gist:1510613
Created December 22, 2011 15:06 — forked from anarchivist/gist:263281
Accessing Drupal's XMLRPC/Services API from Python
# probably ripped off from somewhere on drupal.org
# requires the services module
import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost/services/xmlrpc')
class DrupalNode:
def __init__(self, title, body, path, ntype='page', uid=1, username='mmatienzo'):
self.title = title
@level09
level09 / pyxmlrpc
Created December 23, 2011 16:01
Create Drupal Node with python thorough XMLRPC Service
#! /usr/bin/python
import xmlrpclib, pprint
class DrupalNode:
def __init__(self, title, body, ntype='article', uid=1, username ='admin'):
self.title = title
self.body = body
self.type = ntype
@level09
level09 / redis.markdown
Created January 18, 2012 16:36 — forked from bdotdub/redis.markdown
Running redis using upstart on Ubuntu

Running redis using upstart on Ubuntu

I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis onto the box and here's how I did it and some things to look out for.

To install:

Django-celery + Redis notes

Installation and Setup

  1. Install redis on OSX (10.7) Lion I used:

     $ brew install redis
    
  2. In the project and virtualenv I wanted to use django-celery in I installed the following.

@level09
level09 / gist:2567488
Created May 1, 2012 11:40
Write file in php
function write($path, $content, $mode="w+")
{ if (file_exists($path) && !is_writeable($path)){ return false; } if ($fp = fopen($path, $mode)){ fwrite($fp, $content); fclose($fp); } else { return false; } return true; }
"""
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage.
Do not forget to replace YOURSERVER by the correct value.
Keep in mind that you need the *very latest* version of your web browser.
You also need to add Jacob Kristhammar's websocket implementation to Tornado:
Grab it here:
http://gist.github.com/526746
Or clone my fork of Tornado with websocket included:
http://github.com/pelletier/tornado
Oh and the Pub/Sub protocol is only available in Redis 2.0.0:
@level09
level09 / redis-server.plist
Created May 22, 2012 11:50
Luanchd configuration for redis
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>redis-server</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/redis-server</string>
</array>