Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am somada141 on github.
  • I am adamoscoco (https://keybase.io/adamoscoco) on keybase.
  • I have a public key ASB2iqBiHK6mS_FlhGJxkyOqwbCJnaWK3UNLnDhPimsgSAo

To claim this, I am signing this object:

@somada141
somada141 / schema_with_mutation.py
Created July 11, 2018 01:16 — forked from ssomnoremac/schema_with_mutation.py
mutation example graphene sqlAlchemy
...
class UpdatePersonName(graphene.Mutation):
class Input:
uuid = graphene.Int(required=True)
name = graphene.String(required=True)
person = graphene.Field(Person)
@somada141
somada141 / iterate_pdf_content_python.md
Created July 3, 2017 06:36
Iterate over decoded PDF page content with Python

Introduction

This note shows how to iteratively retrieve the decoded content of the pages in a PDF file using Python and the pdfminer Python package.

At the time of writing, the latest version of pdfminer was used, i.e., 20140328. Thus, as the package seems poorly maintained and prone to API-breaking changes one may have to explicitly install this version for the following code to work.

Code

The following generator will iterate over a PDF file under a given filename and iteratively yield the text content of each PDF page:

@somada141
somada141 / vagrant_prune.md
Created March 13, 2015 03:55
Destroy inaccessible inert VMs in Vagrant #virtualization #vagrant #vm
@somada141
somada141 / replace_line_breaks_bash.md
Created March 10, 2015 21:34
Replace line breaks with spaces in the Bash #linux #bash #shell #string #file

By piping input, e.g., cat <some_file>, to the following command one can replace all line breaks with spaces

sed ':a;N;$!ba;s/\n/ /g'

This will read the whole input, e.g., file, in a loop and then replace the newline(s) with a space.

Explanation:

@somada141
somada141 / check_ubuntu_version_terminal.md
Last active August 29, 2015 14:16
Check Ubuntu version through the terminal #linux #ubuntu #bash #version #shell

This method will work no matter which version of Ubuntu or desktop environment you are running.

  • Open the Terminal (keyboard shortcut: Ctrl+Alt+T)
  • Enter the command lsb_release -a

Your version will be shown on the Description line.

source: https://help.ubuntu.com/community/CheckingYourUbuntuVersion

@somada141
somada141 / python_list_dir.md
Created March 9, 2015 02:45
List all files in the current working directory with Python #python #os

This can be done with the listdir() and getcwd() methods of the os module:

  • os.listdir("path"): lists all files and directories under path which is provided as a string
  • os.getcwd(): returns the full path to the current working directory

usage:

import os
os.listdir(os.getcwd())
@somada141
somada141 / apt_get_install_particular_version.md
Created March 9, 2015 02:40
Install a particular version of a package with apt-get #linux #bash #shell #apt #apt-get #install

You can install a specific version of a package with apt-get in the terminal. First, determine the available versions you can install with the following command:

apt-cache showpkg <packagename>

e.g. apt-cache showpkg subversion-tools would give something like:

> Package: subversion-tools
@somada141
somada141 / build_simpleitk_anaconda.md
Created March 8, 2015 04:52
Build SimpleITK against Anaconda Python on OSX #python #anaconda #conda #simpleitk #itk #build #source #cmake #osx

The following process shows how one would build SimpleITK (from source) to link against and work with the Anaconda Python environment on Mac OSX.

The majority of this process can be applied to other non-vanilla Python interpreters such as Enthought Canopy and Enthough Python Distribution (EPD). This process has also been tried on Windows 7 with Canopy.

Here's how one would go about building SimpleITK against their Anaconda Python:

  • Activate your preferred conda environment. I will assume its called py27 but be careful to amend appropriately and activate through source activate <environment_name>
  • Go to this link: http://www.itk.org/Wiki/SimpleITK/GettingStarted#Build_It_Yourself and take a look at the instructions for building SimpleITK first.
  • Make sure you have CMake installed (I used the 2.8.12 version while writing this but you may want to opt for the newest CMake version first).
  • Make sure you have
@somada141
somada141 / python_dicom_load_vtk.md
Last active March 25, 2024 07:41
Load DICOM data into a NumPy array with VTK #python #dicom #medical #imagedata #vtk #fileIO

Imports:

import vtk
from vtk.util import numpy_support
import numpy

Create a vtkDICOMImageReader object, set its directory to the one containing all DICOM files, and Update to read in all data: