Skip to content

Instantly share code, notes, and snippets.

import hashlib
h = hashlib.new('sha256')
h.update(str)
print h.hexdigest()
@samisalkosuo
samisalkosuo / gist:c0811e968d905420b194
Last active August 29, 2015 14:10
Open port in iptables firewall
#Open firewall for port
FW_PORT=9877
iptables -I INPUT 1 -p tcp -m tcp --dport $FW_PORT -j ACCEPT
iptables -I INPUT 1 -p tcp -m tcp --sport $FW_PORT -j ACCEPT
iptables -I OUTPUT 1 -p tcp -m tcp --sport $FW_PORT -j ACCEPT
iptables -I OUTPUT 1 -p tcp -m tcp --dport $FW_PORT -j ACCEPT
#save firewall rules
/sbin/service iptables save
/sbin/service iptables restart
@samisalkosuo
samisalkosuo / Deploy_Oracle.sh
Last active June 17, 2022 09:37
Oracle 12c silent installation files, including response files. Start installation executing Deploy_Oracle.sh. See also here: http://sami.salkosuo.net/silent-service/.
#!/bin/sh
#Set up Linux and oracle
echo "Deploying Oracle..."
if [[ "$1" != "" ]] ; then
DEFAULT_PWD=$1
echo "Using user specified default password"
else
DEFAULT_PWD=passW0RD
@samisalkosuo
samisalkosuo / changestr.sh
Created December 10, 2014 10:33
Change string in file.
#!/bin/sh
#change string in file
if [[ $# -ne 3 ]]; then
echo "Wrong number of arguments"
echo "Usage: $0 FILE FROMSTRING TOSTRING"
exit 1
fi
SED_FILE=$1
@samisalkosuo
samisalkosuo / gist:203a580a9c7e901377e7
Last active August 29, 2015 14:13
Multiply-with-carry pseudo random number generator by George Marsaglia. Code from: http://en.wikipedia.org/wiki/Random_number_generation
m_w = 0x46ab2f73d #must not be zero, nor 0x464fffff
m_z = 0xa368bbec #must not be zero, nor 0x9068ffff
def mwc():
global m_w
global m_z
m_z = 36969 * (m_z & 65535) + (m_z >> 16)
m_w = 18000 * (m_w & 65535) + (m_w >> 16)
return (m_z << 16) + m_w #32-bit result
@samisalkosuo
samisalkosuo / getpragpub.sh
Created January 20, 2015 10:35
Shell script to get all PragPub magazines.
#!/bin/sh
echo "Retrieving all 49 issues of PragPub as epub..."
echo "Downloading files to $DIR..."
DIR=pragpub
mkdir $DIR
function getPragPub {
#!/bin/sh
bc << EOF
scale=4
$@
quit
EOF
@samisalkosuo
samisalkosuo / rapod.py
Created February 10, 2015 15:30
Random Astronomy Picture of the Day from http://apod.nasa.gov/.
#!/usr/bin/python
#retrieve random Astronomy Picture of the Day
#from http://apod.nasa.gov/
import sys
import datetime
import urllib
import urllib2
import random
@samisalkosuo
samisalkosuo / deploy_i2iap.sh
Created June 24, 2015 07:24
Script to deploy i2 IAP v3.0.11 in IBM PureApplication environment. Check this too: http://sami.salkosuo.net/silent-service-i2-iap/.
echo Deploying i2 IAP 3.0.11 example deployment
function changeString {
if [[ $# -ne 3 ]]; then
echo "$FUNCNAME ERROR: Wrong number of arguments. Requires FILE FROMSTRING TOSTRING."
return 1
fi
SED_FILE=$1
FROMSTRING=$2
@samisalkosuo
samisalkosuo / maze.py
Last active November 17, 2017 03:52
Some mazes classes translated from Ruby from book: Mazes for Programmers (https://pragprog.com/book/jbmaze/mazes-for-programmers). Used in MazinGame: https://github.com/samisalkosuo/mazingame
#!/usr/bin/env python
#Some mazes classes translated from Ruby
#from book "Mazes for Programmers" by Jamis Buck.
#https://pragprog.com/book/jbmaze/mazes-for-programmers
#
#Includes modifications.
#
#Execute this and you see mazes.