Skip to content

Instantly share code, notes, and snippets.

View chmouel's full-sized avatar
🤨
Kuberneting

Chmouel Boudjnah chmouel

🤨
Kuberneting
View GitHub Profile
@chmouel
chmouel / rackspace-cloudfiles-uk.java
Created December 23, 2010 13:59
Rackspace UK CloudFiles access
package com.chmouel.ukcloud.test;
import java.util.Properties;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
public class Main {
public static void main(String[] args) {
@chmouel
chmouel / rackspace-cloudservers-uk.java
Created December 23, 2010 14:14
Access to UK Cloud Servers from jClouds
package com.chmouel.ukcloud.test;
import static org.jclouds.rackspace.cloudservers.options.ListOptions.Builder.withDetails;
import java.util.Properties;
import java.util.Set;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.rackspace.cloudservers.CloudServersClient;
@chmouel
chmouel / rackspace-uk-libcloud.py
Created December 23, 2010 14:22
Access Rackspace UK cloud from libcloud
from libcloud.types import Provider
from libcloud.providers import get_driver
RACKSPACE_USER="USERNAME"
RACKSPACE_KEY="API_KEY"
Driver = get_driver(Provider.RACKSPACE_LON)
conn = Driver(RACKSPACE_USER, RACKSPACE_KEY)
print conn.list_nodes()
@chmouel
chmouel / New Type Yasnippet
Created December 28, 2010 19:30
New Type in Java Yasnippet.
# -*- mode: snippet -*-
# name: newt
# --
${1:TYPE} ${1:$(downcase text)} = new $1();
$0
@chmouel
chmouel / short-url-and-copy-clipboard-macosx.sh
Created January 3, 2011 20:23
Shorten URL and copy to clipboard for MacOSX
#!/bin/bash
CURRENT_SEL=$(pbpaste)
if [[ -n $1 ]];then
URL=$1
fi
if [[ -z $URL ]];then
if [[ ${CURRENT_SEL} == http://* ]];then
@chmouel
chmouel / guess-file-magic-without-python-magic.py
Created January 11, 2011 13:44
Guess file magic without using python-magic
#!/usr/bin/python
# -*- encoding: utf-8 -*-
__author__ = "Chmouel Boudjnah <[email protected]>"
binhexjpg="ffd8ffe000104a464946"
import sys
import binascii
if len(sys.argv) >= 2:
ff = sys.argv[1]
else:
@chmouel
chmouel / get-current-ip.el
Created February 22, 2011 22:23
Get your current IP in Emacs Lisp
(defun get-ip (interface)
(save-excursion
(with-temp-buffer
(call-process "/sbin/ifconfig" nil t nil "-a")
(goto-char (point-min))
(when (re-search-forward interface nil t)
(case system-type
(gnu/linux (re-search-forward "inet addr:\\([^ ]*\\)"))
(darwin (re-search-forward "inet \\([^ ]*\\)" nil t)))
(buffer-substring (match-beginning 1)
@chmouel
chmouel / reboot-cs.py
Created March 17, 2011 12:05
rebout cloudservers
"""
Reboot server by ID
Requirement: python-cloudservers library from
https://github.com/chmouel/python-cloudservers
"""
import cloudservers
# Server ID to shut-down
SERVER_ID = 10010547
@chmouel
chmouel / rackspace-cs-cf-pure-python.py
Created March 29, 2011 15:11
Use RackSpace Cloud Servers/File directly in python without binding
''' Implement a client for Rackspace Cloud Servers or Cloud
Files using pure python.
'''
import httplib
import urlparse
def get_auth(username, key, auth_url):
u = urlparse.urlparse(auth_url)
cls = u.scheme == 'https' and \
@chmouel
chmouel / testport.sh
Created April 6, 2011 10:53
Quickly Test if a port is open.. and
python -c 'import socket;s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.connect(("localhost", 2022))' >/dev/null 2>/dev/null || blah_launch_server