Skip to content

Instantly share code, notes, and snippets.

@konyavic
konyavic / kmeans.swift
Created February 14, 2019 00:57
K-Means by Swift Playground
func argmin(_ xs: [Double]) -> Int {
var argmin = 0
var min = xs[0]
for (i, x) in xs[1..<xs.count].enumerated() {
if (min > x) {
argmin = i + 1
min = x
}
}
@konyavic
konyavic / Makefile
Last active April 25, 2018 10:51
test_objc_ivar_accessor
LDFLAGS=-lobjc -fobjc-arc -framework Foundation
CFLAGS=-O0 -g
all: test_objc_ivar_accessor
clang -O0 $(LDFLAGS) -S -o test_objc_ivar_accessor.s test_objc_ivar_accessor.m
clean:
rm -rf *.s *.o test_objc_ivar_accessor *.dSYN
.o: .m
@konyavic
konyavic / transfer.py
Created June 20, 2017 06:04
python script for transferring ownership of all files on Google Drive
#!/usr/bin/env python
from __future__ import print_function
import httplib2
import os
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
@konyavic
konyavic / twittercrawler.py
Created February 17, 2016 03:40
twitter crawler for python 2.7 using python-twitter
# coding: utf-8
import twitter
import argparse
class TwitterCrawler:
def __init__(self):
self.api = twitter.Api(
# credential and token
"",
"",
@konyavic
konyavic / gist:302b22154e39f177cfab
Created August 1, 2014 06:42
Wrap output from utf-8 to utf-16, also deal with escape sequence with ansi color
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import subprocess
reload(sys)
sys.setdefaultencoding("utf-16")
HAS_COLORAMA = True
@konyavic
konyavic / gist:2babd997204aac16f21b
Created June 30, 2014 07:59
vmx for osx (not works #2)
.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "10"
memsize = "1024"
ethernet0.present = "TRUE"
ethernet0.connectionType = "nat"
ethernet0.virtualDev = "e1000"
ethernet0.wakeOnPcktRcv = "FALSE"
ethernet0.addressType = "generated"
ethernet0.linkStatePropagation.enable = "FALSE"
@konyavic
konyavic / gist:42ef808e31cd5bb3edc5
Created June 30, 2014 07:58
vmx for osv (not works)
.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "10"
scsi0.present = "TRUE"
scsi0.virtualDev = "pvscsi"
memsize = "2048"
ethernet0.present = "TRUE"
ethernet0.connectionType = "nat"
ethernet0.virtualDev = "vmxnet3"
ethernet0.addressType = "generated"
@konyavic
konyavic / gist:7d1551c472a1674fe7c5
Created June 30, 2014 07:58
vmx for osv (works)
#!/usr/bin/vmware
.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "10"
scsi0.present = "TRUE"
scsi0.virtualDev = "pvscsi"
memsize = "1024"
ethernet0.present = "TRUE"
ethernet0.connectionType = "nat"
ethernet0.virtualDev = "vmxnet3"
@konyavic
konyavic / gist:1b0e61671e3109e34bd2
Last active August 29, 2015 14:02
Google Drive ls -R
def list_recursively(id, dir="", maxResults=100):
children = []
query_result = drive_service.files().list(
q='"%s" in parents' % id,
maxResults=maxResults
).execute()
while True:
children += query_result['items']
if not 'nextPageToken' in query_result:
break
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 1 (delta 0)
Unpacking objects: 100% (1/1), done.
fatal: final sha1 did not match
fatal: unpack-objects failed