Skip to content

Instantly share code, notes, and snippets.

@shturm
shturm / a2addsite.py
Last active January 1, 2016 05:29
Simple python script for adding sites in Ubuntu 12.04+. Given a <site-name> it: Creates /var/www/<site-name> folder, Sets 0777 permissions to the document root, Creates and enables a virtual host configuration, Reloads apache2 web server. Has option --mysql for creating a mysql database for the site
#!/usr/bin/python
import sys
import os
import getpass
from subprocess import call, PIPE, Popen
if (len(sys.argv) == 1 or sys.argv[1] == 'help'):
print "Usage is:\n\tsudo a2addsite <site-name> [--mysql]"
print "Parameters:"
@shturm
shturm / SublimeJSConsoleLog.sublime-snippet
Created March 3, 2014 13:01
Sublime text 2/3 snippet for console.log() in Javascript. To install place the file with this content in Linux: ~/.config/sublime-text-3/Packages/User/consolelog.sublime-snippet or Windows: SUBLIMEINSTALLROOT\Packages\User\consolelog.sublime-snippet. The actual file name doesn't matter, only the extension does.
<snippet>
<content><![CDATA[
console.log(${1:'${2:}'});
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>con</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.js</scope>
</snippet>
function problem4(input) {
var matches = [],
players = [];
// create matches from input
for (var i = input.length - 1; i >= 0; i--) {
var line = input[i];
var match = {
playerA: getFirstPlayer(line),
playerB: getSecondPlayer(line),
@shturm
shturm / Preferences.sublime-settings
Created May 16, 2015 15:36
User preferences for sublime - Preferences > Settings - User
{
"folder_exclude_patterns":
[
".svn",
".git",
".hg",
"CVS",
"node_modules",
"bower_components",
"tmp"
@shturm
shturm / index.html
Last active September 1, 2015 14:51 — forked from anonymous/index.html
Ember Testing - Fixtures/Mockjax. Source from: http://jsbin.com/yurope/6
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Ember testing approaches">
<meta charset="utf-8">
<title>Ember Testing</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script src="http://builds.emberjs.com/tags/v1.10.0/ember-template-compiler.js"></script>
@shturm
shturm / index.js
Created September 16, 2015 11:53
NodeJS HTTP Server
//Lets require/import the HTTP module
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.end('It Works!! Path Hit: ' + request.url);
}
# Restore a complete copy of the SSD (sda device)
gunzip -c /media/data/IMAGE_NAME.img.tgz | dd of=/dev/sda
# Create and compress complete backup of sda (the SSD) disk
dd if=/dev/sda conv=sync,noerror bs=1k | gzip -c > IMAGE_NAME.img.tgz
# Remove LVM the snapshot
sudo lvremove /dev/ubuntuvg/rootsnap
# Create LVM snapshot
@shturm
shturm / makeself-exec.sh
Created January 26, 2016 10:14
Execute makeself script from anywhere (https://github.com/megastep/makeself)
MAKESELFPATH=/home/alx/bin/makeself
PAYLOADFOLDER=$(readlink -e $1)
OUTPUTFILENAME=$(pwd)/$2
LABEL=$3
INSTALLER=$(readlink -e $4)
cd $MAKESELFPATH
echo "Executing: sh makeself.sh $PAYLOADFOLDER $OUTPUTFILENAME $LABEL $INSTALLER"
sh makeself.sh $PAYLOADFOLDER $OUTPUTFILENAME $LABEL $INSTALLER

Restore a complete copy of the SSD (sda device)

gunzip -c /media/data/IMAGE_NAME.img.tgz | dd of=/dev/sda

Create and compress complete backup of sda (the SSD) disk

dd if=/dev/sda conv=sync,noerror bs=1k | gzip -c > IMAGE_NAME.img.tgz

Remove LVM the snapshot

sudo lvremove /dev/ubuntuvg/rootsnap

Create LVM snapshot

using System;
using System.Text;
using System.Runtime.InteropServices;
using RGiesecke.DllExport; // https://www.nuget.org/packages/UnmanagedExports - required for the functions to be consumed by native code
namespace Testme
{
class Test
{