Skip to content

Instantly share code, notes, and snippets.

View MrZoidberg's full-sized avatar

Mikhail Merkulov MrZoidberg

View GitHub Profile
@MrZoidberg
MrZoidberg / OpenFileWithRetry.cs
Created October 12, 2012 13:17
C# FileStream Lock. How to wait for a file to get released and lock safely.
public static FileStream OpenFileWithRetry(string path, FileMode mode, FileAccess fileAccess, FileShare fileShare)
{
ArgumentsChecker.ArgumentNotNull(path, "path");
var autoResetEvent = new AutoResetEvent(false);
while (true)
{
try
{
@MrZoidberg
MrZoidberg / SmartTrackingDictionary.cs
Created November 27, 2012 22:01
Dictionary that smartly track changes of the values
class Program
{
static void Main(string[] args)
{
var dict = new SmartTrackingDictionary<string, object>();
dict["int"] = 1;
dict["int"] = 2;
Console.WriteLine("key 'int' {0}", dict.IsChanged("int") ? "has changed" : "hasn't changed");
dict["str"] = "string1";
dict["str"] = "string2";
#!/usr/bin/python
# -*- coding: utf-8 -*-
import web, json, time, mpd, collections
STATIONS = {
"FoxNews" : "mmsh://209.107.209.181:80/D/138/13873/v0001/reflector:24137?MSWMExt=.asf",
"Classic" : "http://radio02-cn03.akadostream.ru:8100/classic128.mp3",
"Jazz": "http://streaming208.radionomy.com:80/A-JAZZ-FM-WEB"
}
<!DOCTYPE html>
<html>
<head>
<title>Radio RPi</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css"/>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
static BOOL PSPDFIsDevelopmentBuild(void) {
#if TARGET_IPHONE_SIMULATOR
return YES;
#else
@autoreleasepool {
// There is no provisioning profile in AppStore Apps.
NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
if (data) {
const char *bytes = [data bytes];
NSMutableString *profile = [NSMutableString new];
@MrZoidberg
MrZoidberg / xcode-build-bump.sh
Created December 19, 2013 23:47
Auto-increment the build number every time the project is run.
# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
@MrZoidberg
MrZoidberg / xcode-version-bump.sh
Created December 19, 2013 23:48
Auto-increment the version number (only) when a project is archived for export.
# xcode-version-bump.sh
# @desc Auto-increment the version number (only) when a project is archived for export.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Check the checkbox "Run script only when installing"
# 6. Drag the "Run Script" below "Link Binaries With Libraries"
# 7. Insure your starting version number is in SemVer format (e.g. 1.0.0)
@MrZoidberg
MrZoidberg / mapbox-background.m
Last active August 29, 2015 13:56
Mapbox background rendering HOW-TO
//First of all you need to modify your Mapbox SDK with the this commit:
//https://github.com/MrZoidberg/mapbox-ios-sdk/commit/2865d642f163b15f939a906337de4f53bd17a7b6
//Otherwise you will have random crashes during background rendering of maps
//We need semaphore to limit the number of concurrent threads
//Place it one per view
dispatch_semaphore_t _concurrencyLimitingSemaphore = dispatch_semaphore_create(3);
//Also we need cache to store snapshots of the map
NSCache *_imageCache = [NSCache new];
@MrZoidberg
MrZoidberg / SmartDateTime.cs
Last active August 29, 2015 14:02
DateTime struct with support of parsing and storing dates like this: {CURRENT_DATE}+1h5m2s
[Serializable]
public struct SmartDateTime : IFormattable, ISerializable, IXmlSerializable, IEquatable<SmartDateTime>, IConvertible
{
private bool _current;
private TimeSpan _diff;
private DateTime _value;
public bool IsCurrent
{
get { return _current; }
@MrZoidberg
MrZoidberg / bobuktask.cs
Last active December 14, 2017 14:47
Задачка Бобука
///Из заданного списка вывести поочередно, рандомно, а главное, без повторений, все его элементы.
public struct Banner
{
public int id;
public string url;
}
class Program
{
private static List<Banner> _banners;