Skip to content

Instantly share code, notes, and snippets.

View komuw's full-sized avatar

Komu Wairagu komuw

View GitHub Profile
#python script for fibonacci between 1 and 100
#example: 1,2,3,5,8,13
hold=[]
temp1 = 1
temp2 = 2
hold.append(temp1); hold.append(temp2)
for i in range(3, 101):
temp3 = temp1 + temp2
@komuw
komuw / install ubuntu crouton
Last active August 29, 2015 14:11
install ubuntu via crouton in a chromebook
1. open a browser and go to https://goo.gl/fd3zc, that will download crouton
2. hit Ctrl+alt+T and then type shell and press enter
$ shell
3. install ubuntu via
$ sudo sh ~/Downloads/crouton -r trusty -t xfce
#that will install ubuntu 14.04 with xfce desktop environment
4. to list available versions:
@komuw
komuw / gist:caeb33a164d0d6d6310a
Created January 5, 2015 09:04
output log for vagrant up
INFO global: Vagrant version: 1.7.1
INFO global: Ruby version: 2.0.0
INFO global: RubyGems version: 2.0.14
INFO global: VAGRANT_EXECUTABLE="/opt/vagrant/bin/../embedded/gems/gems/vagrant-1.7.1/bin/vagrant"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="/opt/vagrant/bin/../embedded"
INFO global: VAGRANT_INSTALLER_VERSION="2"
INFO global: VAGRANT_DETECTED_OS="Linux"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_INTERNAL_BUNDLERIZED="1"
INFO global: VAGRANT_LOG="debug"
@komuw
komuw / gist:fb746bbb85ddcc3d00ac
Created January 29, 2015 09:07
ansible execute bash script
name: execute bash script
command: bash {{ APP_DIR }}/some_script.sh
@komuw
komuw / django 1.3wsgi.py
Created March 17, 2015 11:27
django 1.3 wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
# This application object is used by the development server
# as well as any WSGI server configured to use this file.
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
@komuw
komuw / gist:5b37ad11a320202c3408
Last active August 29, 2015 14:21
generate server cert,key and client certificate and use them in Nginx.
#Taken from:
http://nategood.com/client-side-certificate-authentication-in-ngi
#reposted here to preserve history
#see: https://gist.github.com/komuW/076231fd9b10bb73e40f for a bash script to auto-generate all this
Client Side Certificate Auth in Nginx
Why Client-Side Certificate Authentication? Why nginx?
I sometimes peruse the ReST questions of stackoverflow.com. Many times I see questions about authentication. There are many options (Basic HTTP Auth, Digest HTTP Auth, OAuth, OAuth Wrap, etc.) however when security is of importance, I like to recommend client side certificates. This is the route our team at ShowClix chose when implementing our API.
@komuw
komuw / fake(mock) datetime in python (django)
Created June 2, 2015 09:17
fake(mock) datetime in python (django)
class DateTimefaker(datetime):
"""
fake datetime to use your own custom datetimes
"""
def __new__(cls, *args, **kwargs):
return datetime.__new__(datetime, *args, **kwargs)
class TestSomething(TestCase):
fixtures = ['test_data']
@komuw
komuw / read_from_mem.py
Last active August 29, 2015 14:24
python read file from memory
# We compare/measure reading a file from memory(1) vs reading from filesytem(2)
##################################
### 1. reading file from memory ##
##################################
import time
import mmap
filename = "myfile.txt"
@komuw
komuw / test_xml.py
Created July 2, 2015 13:31
test xml in django/ rest framework
from rest_framework.test import APIClient
class SomeTests(LiveServerTestCase):
def setUp(self):
self.real_URL = settings.SOME_URL
settings.SOME_URL = '{0}/some-url/'.format(self.live_server_url)
self.client = APIClient()
self.payload = """<some>xml-string</xml>"""
@komuw
komuw / http_handlers.go
Last active August 29, 2015 14:24
answer to a tour of go exercise on http handlers(web servers) https://tour.golang.org/methods/14
package main
import (
"fmt"
"net/http"
)
type Mystring string
type Mystruct struct {