Skip to content

Instantly share code, notes, and snippets.

@stansidel
stansidel / watching_timeouts.js
Created February 26, 2016 07:23
Script allows for watching JavaScript timeouts (intervals, timers) being created and cleared. Useful in debugging purposes.
window.originalSetTimeout=window.setTimeout;
window.originalClearTimeout=window.clearTimeout;
window.activeTimers=[];
window.setTimeout=function(func,delay)
{
var id = window.originalSetTimeout(func,delay);
window.activeTimers[id] = {"func": func, "delay": delay};
return id;
};
@stansidel
stansidel / LocationManagerGeocoder.swift
Created March 4, 2016 08:07
UCI9DC L78 Location Aware App
// MARK: - CLLocationManagerDelegate
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
var text = "location: \(location.coordinate.latitude), \(location.coordinate.longitude)\n"
text += "course: \(location.course)\n"
text += "speed: \(location.speed)\n"
text += "altitude: \(location.altitude)\n"
CLGeocoder().reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
if error != nil {
@stansidel
stansidel / AppDelegate.swift
Last active March 27, 2016 06:31
Parse Server initialisation in iOS as told on Udemy
let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in
ParseMutableClientConfiguration.applicationId = "myAppId"
ParseMutableClientConfiguration.clientKey = "myMasterKey" // This is wrong! Never put your master key into the sources.
ParseMutableClientConfiguration.server = "https://anotherdarntest.herokuapp.com/parse"
})
Parse.initializeWithConfiguration(parseConfiguration)
@stansidel
stansidel / index.js
Last active March 27, 2016 08:17
Parse Server with the ALLOW_CLIENT_CLASS_CREATION setting
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
},
allowClientClassCreation: process.env.CLIENT_CLASS_CREATION || false // <<< This line is added for disabling client class creation
@stansidel
stansidel / NSData+Hashes.swift
Last active March 22, 2022 14:51
Getting MD5 and SHA256 of NSData and String in Swift
extension NSData {
private func getHash(
algorithm: (UnsafePointer<Void>, CC_LONG, UnsafeMutablePointer<UInt8>) -> UnsafeMutablePointer<UInt8>,
digestLength: Int32
) -> String {
let digestLen = Int(digestLength)
let fileLen = CUnsignedInt(self.length)
let buffer = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
algorithm(self.bytes, fileLen, buffer)
@stansidel
stansidel / gpg-with-key
Last active November 10, 2023 08:20
Setting up GPG signature on Mac OS X with Xcode
/usr/local/bin/gpg --batch --passphrase-file ~/.gnupg/key.txt --no-tty "$@"
@stansidel
stansidel / bittorrent_sync_private_permissions.sh
Last active May 17, 2016 06:29
Setting correct ACLs for a private directory under BitTorrent Sync
# See https://www.thomaskeller.biz/blog/2011/06/04/acls-on-mac-os-x/
$ cd ~/bittorrent
$ mkdir private
$ chmod -R +a '<username> allow read,write,delete,add_file,add_subdirectory,file_inherit,directory_inherit' private
$ chmod -R +a# 1 'everyone deny read,write,delete,add_file,add_subdirectory,file_inherit,directory_inherit' private
@stansidel
stansidel / description.md
Created May 23, 2016 09:46
1C Accounting 3.0 Bill XML Format

Обязательные параметры счета в файле XML:

  • Дата;
  • Номер - будет соответствовать номеру на сайте?
  • Контрагент;
  • Договор с контрагентом – будет браться из основного договора контрагента;
  • Банковский счет;
  • Товары и услуги:
    • Номенклатура;
    • Количество;
  • Цена ;
@stansidel
stansidel / SelectImageVC.swift
Created July 4, 2016 11:15
Presenting UIAlertController for uploading a photo
@IBAction func loadImage(sender: AnyObject) {
let imagePickerActionSheet = UIAlertController(title: "Take/Upload Photo",
message: nil, preferredStyle: .ActionSheet)
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
let cameraButton = UIAlertAction(title: "Take Photo", style: .Default, handler: { (alert) in
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
self.presentViewController(imagePicker, animated: true, completion: nil)
})
@stansidel
stansidel / sample.swift
Created August 24, 2016 08:05
Reading input and writing to stderr in Swift (for programming challenges)
import Foundation
public struct StderrOutputStream: OutputStreamType {
public mutating func write(string: String) { fputs(string, stderr) }
}
public var errStream = StderrOutputStream()
let T = Int(readLine()!)!
debugPrint("T = \(T)", toStream: &errStream)