Skip to content

Instantly share code, notes, and snippets.

View drmalex07's full-sized avatar

MichailAlexakis drmalex07

  • IMIS "Athena" Research Center
  • Athens, Greece
View GitHub Profile
@drmalex07
drmalex07 / unpack-zipfile-example.py
Created April 6, 2014 12:16
A simple example of using ZIP archives in Python. #python #zip #zipfile
import sys
import os.path
import zipfile
target_dir = os.path.join('/tmp', 'unpacked')
target_zipfile = sys.argv[1]
print '[info] Using zip file: ' + target_zipfile
assert zipfile.is_zipfile(target_zipfile), 'The given file %s is corrupted!' %(target_zipfile)
@drmalex07
drmalex07 / child-hello-1.bat
Last active August 29, 2015 13:58
An example of spawning/waiting for processes inside a batchfile. #batchfile #msdos #cmd.exe-start #cmd.exe
ping -n 4 127.0.0.1
echo "Hello World #1"
del active.1
@drmalex07
drmalex07 / helloworld-win32-service.py
Created April 12, 2014 20:08
An example Windows service implemented with pywin32 wrappers. #python #windows-service #pywin32
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import time
import logging
logging.basicConfig(
filename = 'c:\\Temp\\hello-service.log',
@drmalex07
drmalex07 / foo-drupal-stream.php
Created April 15, 2014 11:39
A skeleton (stub methods) for a Drupal stream wrapper implementation. #drupal #php #stream-wrapper
<?php
class Foo_Stream implements DrupalStreamWrapperInterface
{
const SCHEME = 'foo';
const EXTERNAL_PATH_PREFIX = 'public/files/foo';
public $context;
protected $uri;
@drmalex07
drmalex07 / test-pear-net_ftp-1.php
Created April 15, 2014 17:42
An example with Pear Net_FTP FTP client. #ftp #net_ftp #php #pear
<?php
require_once ('Net/FTP.php');
$host = 'ftp.example.com';
$user = 'guest';
$pass = 'guest';
$ftp = new Net_FTP();
@drmalex07
drmalex07 / drupal7-multistep-form-example.php
Created April 20, 2014 06:29
An example with multistep forms in drupal7. #drupal #drupal7 #multistep-form
<?php
function helloworld_multistep_example_form($form, &$form_state)
{
// We add 2 keys to form_state ("step" and "state") to keep track
// of state in a multistep form.
$step = isset($form_state['step'])? ($form_state['step']) : (1);
$form['heading'] = array(
'#type' => 'markup',
@drmalex07
drmalex07 / backbone-router-example-1.js
Created April 21, 2014 19:43
An example with Backbone.js Router. #backbone #javascript #backbone-router
Application = Backbone.Router.extend({
routes: {
"help": "help", // #help
"search/:query": "search", // #search/kiwis
"search/:query/page/:page": "search" // #search/kiwis/page/7
},
help: function()
{
@drmalex07
drmalex07 / create-pear-environment.md
Last active August 29, 2015 14:00
Create an isolated PHP PEAR environment. #php #php-pear

Follow the instructions at PEAR installation and download PEAR package.

wget http://pear.php.net/go-pear.phar 

Install PEAR and specify the prefixes when propmted: for example, use /usr/local as prefix and /usr/local/etc/pear.conf as PEAR configuration file.

php go-pear.phar

After installation, you can optionally add /usr/local/bin to your shell's PATH. In order to use PEAR, you must always provide the config file as a command-line argument (or PEAR will use the system's default path):

@drmalex07
drmalex07 / codemirror-example.html
Created April 26, 2014 13:44
Example use of CodeMirror as javascript code editor. #javascript #javascript-editor #codemirror
<html lang="en">
<head>
<title>CodeMirror in Action</title>
<script src="js/vendor/jquery-1.9.1.js"></script>
<!-- More examples at http://codemirror.net/demo/ -->
<!-- add basic CodeMirror functionality -->
<script src="js/vendor/codemirror-4.1/lib/codemirror.js" type="text/javascript" charset="utf-8"></script>
@drmalex07
drmalex07 / prettify-example.html
Created April 29, 2014 07:36
An example of using prettify.js to highlight a PRE code region in HTML. #javascript #prettify
<script type="text/javascript" src="js/vendor/prettify/prettify.js"></script>
<link rel="stylesheet" href="js/vendor/prettify/prettify.css" />
<script type="text/javascript">
var json_dump = JSON.stringify({'foo': 'bar', 'x': 15}, null, 4)
var $pre1 = $("<pre/>")
.addClass(['prettyprint', 'linenums', 'lang-js'].join(' '))
.text(json_dump);
this.$el.find("#results-body").append($pre1);
prettyPrint();