Skip to content

Instantly share code, notes, and snippets.

View msuzen's full-sized 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 January 24, 2019 17:12
Matlab like tic toc functions in Python
# 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 January 19, 2018 08:29
Traverse nested dictionary in Python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 4 11:48:48 2017
@author: msuzen
"""
#'
@msuzen
msuzen / readFileToStringNode.js
Last active January 2, 2018 14:07
node.js read a text file to a string
/*
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 June 10, 2017 14:32
Simple try/catch in 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 March 2, 2017 16:35
An example usage of apt from python programmatically
#
# 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 February 27, 2017 15:36
OO is a bad idea
"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 February 27, 2017 15:45
An example on using arbitrary number of arguments with Python 3
"""
(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 June 17, 2017 19:19
Spark RDD partition size after reduction of the data size
/*
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 August 29, 2015 14:18
Scale back or transform back multiple linear regression coefficients: Arbitrary case with ridge regression
# (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),