Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
We are all finite objects on an unbounded n-D surface.

Mehmet Süzen msuzen

💭
We are all finite objects on an unbounded n-D surface.
View GitHub Profile
@msuzen
msuzen / tic_toc.py
Last active Jan 24, 2019
Matlab like tic toc functions in Python
View tic_toc.py
# To measure timing
#' http://stackoverflow.com/questions/5849800/tic-toc-functions-analog-in-python
def tic():
# Homemade version of matlab tic and toc functions
import time
global startTime_for_tictoc
startTime_for_tictoc = time.time()
def toc():
import time
@msuzen
msuzen / traverse_nested_dict.py
Last active Jan 19, 2018
Traverse nested dictionary in Python
View traverse_nested_dict.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 4 11:48:48 2017
@author: msuzen
"""
#'
@msuzen
msuzen / readFileToStringNode.js
Last active Jan 2, 2018
node.js read a text file to a string
View readFileToStringNode.js
/*
By msuzen GPLv3
See Also: https://stackoverflow.com/questions/3133243/how-do-i-get-the-path-to-the-current-script-with-node-js
*/
var fs = require('fs');
var shapes = fs.readFile(process.cwd() + '/' + options.shapes, function(err, data)
{
if(err)
console.log(err)
@msuzen
msuzen / try_catch_simple_R
Created Jun 10, 2017
Simple try/catch in R
View try_catch_simple_R
R Notes:
# tryCath Example
# http://stackoverflow.com/questions/12193779/how-to-write-trycatch-in-r
out <- tryCatch({
pp <- find.package(packageName,lib.loc=lib.loc),
},
error=function(cond) {
cat("packageName or lib.loc in ",
"packageRSubdirectoryLinesOfCode",
"does not seem to exist \n")
@msuzen
msuzen / apt_python_sample.py
Created Mar 2, 2017
An example usage of apt from python programmatically
View apt_python_sample.py
#
# An example usage of apt from python programmatically
#
#
import apt # use apt-get to install somehow pip has an issue
import apt_pkg
apt_pkg.init_config()
apt_pkg.init_system()
cache = apt_pkg.Cache() # all cache packages
ipacks = [pack for pack in cache.packages]
@msuzen
msuzen / txt
Created Feb 27, 2017
OO is a bad idea
View txt
"Object-oriented programming is an exceptionally bad idea which could only have originated in California."
(Edsger Dijkstra, (Dutch computer Scientist, 1930-2002)
@msuzen
msuzen / msum_map.py
Last active Feb 27, 2017
An example on using arbitrary number of arguments with Python 3
View msum_map.py
"""
(c) 2017
Creative Commons Licence
This work is licensed under a Creative Commons Attribution 3.0 Unported License.
"""
import functools as ft
# Example on using arbitrary number of arguments
def msum(*nums):
'''
@msuzen
msuzen / rddPartitionParent
Last active Jun 17, 2017
Spark RDD partition size after reduction of the data size
View rddPartitionParent
/*
RDD partition size retains from the parent
(c) 2017
GPLv3
Author: Mehmet Suzen (suzen at acm dot org)
*/
// Generate 1 million Gaussian random numbers
@msuzen
msuzen / scaleBackRidge
Last active Aug 29, 2015
Scale back or transform back multiple linear regression coefficients: Arbitrary case with ridge regression
View scaleBackRidge
# (c) Copyright 2008-2015 Mehmet Suzen (suzen at acm dot org)
# Creative Commons Licence
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
#
rm(list=ls())
library(glmnet)
library(R1magic) # https://github.com/msuzen/R1magic
set.seed(4242)
n <- 100 # observations
X <- model.matrix(~., data.frame(x1 = rnorm(n, 1, 1),