Skip to content

Instantly share code, notes, and snippets.

@chulman444
chulman444 / buffer_array_to_binary.js
Created September 12, 2018 03:32
Converts { type: "Buffer", data: [1,2,3,4,...] } to a proper 'raw' file. 😲 WOW 😲 Such πŸ™ USEFUL πŸ™
const fs = require("fs");
function createParser() {
const ArgumentParser = require("argparse").ArgumentParser;
const parser = new ArgumentParser({ });
parser.addArgument(
['filepath'],
{
type: String,
@chulman444
chulman444 / docx_elements_from_docx_files.py
Created June 23, 2018 15:38
Get all docx elements from docx files in a directory tree. Use with this script in this gist (https://gist.github.com/chulman444/b9e0ef2b61a241f47d25746a9a26e9f0)
import sys, os, json, time
from examine_docx_elements import run as getDocxElements
def main():
print("Started")
rootdir = sys.argv[1]
before = time.time()
output = run(rootdir)
after = time.time()
print(output)
@chulman444
chulman444 / examine_docx_elements.py
Last active June 23, 2018 15:15
Docx is a zip file of xml files. There is a XML file which you can parse to get all the used elements in there. Simple enough, but why not share it? This script extracts all XML or Docx elements from a 'docx' file. Unzipping of docx file is done within the script. For docx references, refer to this url. http://officeopenxml.com/anatomyofOOXML.php
try:
from xml.etree.cElementTree import XML
except ImportError:
from xml.etree.ElementTree import XML
import zipfile, re
"""
Module that extract text from MS XML Word document (.docx).
(Inspired by python-docx <https://github.com/mikemaccana/python-docx>)
@chulman444
chulman444 / Android file methods output.txt
Created June 2, 2018 11:41
For some reason, Android file methods confused me, so I just decided to test all outputs and post it here
Environment.getExternalStorageDirectory()
- /storage/emulated/0
Environment.getExternalStoragePublicDirectory("") // Error on `null`
- /storage/emulated/0
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
- /storage/emulated/0/Pictures
getExternalFilesDir(null) // Parameter "" returns the same
@chulman444
chulman444 / getattr__vs__getattribute.py
Created April 27, 2018 03:35
Simple code for understanding `__getattr__` and `__getattribute__`
class MyClass():
def __init__(self):
self.foo = "foo"
# Ignored.
def __getattr__(self, attribute):
print("__getattr__ for {} called".format(attribute))
def __getattribute__(self, attribute):
print("__getattribute__ for {} called".format(attribute))
@chulman444
chulman444 / google_drive_api.py
Created April 25, 2018 05:48
Google Drive API. Simple Get, Create, List, and get content of file.
# Refer to https://developers.google.com/api-client-library/python/
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from googleapiclient.http import MediaFileUpload, MediaIoBaseDownload
import mimetypes, io
from pprint import pprint
class DriveAPI():
def __init__(self):
@chulman444
chulman444 / mods_in_udacity_intro_to_ml_lessons.json
Last active March 19, 2018 11:06
All sklearn modules used in Udacity "Intro to machine learning" lessons. Refer to [here](https://classroom.udacity.com/courses/ud120)
{
"train_test_split": {
"raw": [
"outliers/outlier_removal_regression.py:23:from sklearn.cross_validation import train_test_split",
"regression/finance_regression.py:30:from sklearn.cross_validation import train_test_split",
"pca/eigenfaces.py:26:from sklearn.cross_validation import train_test_split",
"final_project/poi_id.py.bak:52:from sklearn.cross_validation import train_test_split",
"final_project/poi_id.py:67: from sklearn.cross_validation import train_test_split",
"validation/validate_poi.py:32:from sklearn.model_selection import train_test_split",
"evaluation/validate_poi.py:32:from sklearn.model_selection import train_test_split",
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.decomposition import PCA
import numpy as np
X1, Y2 = make_classification(n_features=2, n_informative=2, n_redundant=0,
n_classes=1,
n_clusters_per_class=1)
x0 = X1[:,0]
import yaml
content = """First line
Second line
Third line"""
print("The following is the content")
print(content)

Getting original file from a new or patched file from a diff file.

Instead of diff orig new > diff0 and keeping diff0, and original file,

diff new orig > diff0 then keep the new and diff0 and discard the original file.

Didn't take very long to think of this, but I may forget again.

Having this "I have to come up with a solution" feeling stresses me. ARCHIVED!