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 / git-rebase-example.sh
Created March 14, 2014 12:29
Provide a simple workflow for a git rebase scenario. #git #git-rebase #scm
# Create a branch named "feature-a"
git branch feature-a
# Switch to branch "feature-a" updating your working copy
git checkout feature-a
# Work ...
vim hello.py
vim README
@drmalex07
drmalex07 / intl-datetime-example-1.php
Created March 16, 2014 22:34
An example for a localized formatted date in PHP. #php #datetime #i18n
<?php
$expected_duration = new DateInterval("PT03H30M"); /* 03:30:00 or 3h 30min */
$expected_at = new DateTime('now');
$expected_at->add($expected_duration);
$formatter = new IntlDateFormatter('el_GR', IntlDateFormatter::LONG, IntlDateFormatter::SHORT);
print $formatter->format($expected_at);
@drmalex07
drmalex07 / hg-branch-example-hgrc
Created March 18, 2014 14:08
Provide an example workflow with Mercurial branches. #mercurial #hg #scm
#
# Example configuration for .hgrc
#
[extensions]
extdiff=
graphlog=
@drmalex07
drmalex07 / download-file.py
Created April 6, 2014 11:26
A download helper for Python scripts. #python #download
import sys
import os.path
import urllib2
def download_file(url, dest_file):
try:
ifp = urllib2.urlopen(url, data=None)
with open(dest_file, 'wb') as ofp:
n = 0
s = ifp.read()
@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 / 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 / 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 / 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();