Skip to content

Instantly share code, notes, and snippets.

View andrey-str's full-sized avatar

Andrey Streltsov andrey-str

View GitHub Profile
@andrey-str
andrey-str / ape2mp3.sh
Created January 6, 2016 09:08 — forked from jingle/ape2mp3.sh
Convert ape to mp3 using avconv, split with mp3splt and cue
#!/bin/bash
find "$1" -type f -name "*.ape" -print0 | while read -d $'\0' song
do
output=${song%.ape}.mp3
cue=${song%.ape}.cue
avconv -i "$song" -b 192k "$output"
if ls "$cue" &> /dev/null; then
mp3splt -a -c "$cue" "$output"
@andrey-str
andrey-str / ViewsContainerController.h
Last active March 24, 2016 11:24
UIView Container pattern
//
// Created by Andrey Streltsov on 09/03/16.
//
@import UIKit;
enum eViewControllerIndentifiers {
eIdentifier1, // the one with rendered whole course map
eIdentifier2, // the one with MapKit map
eIdentifier3 // the one with rendered hole map
@andrey-str
andrey-str / mute.sh
Created March 24, 2016 10:09
OS X Volume Up/Down/Mute from Terminal
mute=`osascript -e 'output muted of (get volume settings)'`
if [ $mute = true ]; then mute=false; else mute=true; fi
osascript -e "set volume output muted \"$mute\""
@andrey-str
andrey-str / string-unicode.rb
Created March 31, 2016 11:00
Ruby's String class extension to support Unicode for some operations
require 'unicode'
class String
def downcase
Unicode::downcase(self)
end
def downcase!
self.replace downcase
end
def upcase
@andrey-str
andrey-str / random-color.m
Created April 12, 2016 20:26
Random UI/SK/NSColor snippet(obj-c)
- (UIColor*) randomColor{
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
return color;
}
double delayInSeconds = 0.7;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
// Your code here..
});
@andrey-str
andrey-str / replaceColor.swift
Created April 22, 2016 00:05
Replace color in UIImage with give tolerance value
// color - source color, which is must be replaced
// withColor - target color
// tolerance - value in range from 0 to 1
func replaceColor(color:SKColor, withColor:SKColor, image:UIImage, tolerance:CGFloat) -> UIImage{
// This function expects to get source color(color which is supposed to be replaced)
// and target color in RGBA color space, hence we expect to get 4 color components: r, g, b, a
assert(CGColorGetNumberOfComponents(color.CGColor) == 4 && CGColorGetNumberOfComponents(withColor.CGColor) == 4,
"Must be RGBA colorspace")
@andrey-str
andrey-str / integer.rb
Created April 25, 2016 10:38 — forked from pithyless/integer.rb
Ruby Integer::MAX and Integer::MIN
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
@andrey-str
andrey-str / singleton.m
Created May 4, 2016 13:35 — forked from abbeyjackson/sharedInstance Singleton
sharedInstance singleton
+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
@andrey-str
andrey-str / README.md
Created June 10, 2016 13:28 — forked from cjolly/README.md
How to securely set rails secret key when you deploy to Heroku.

Stop Versioning Rails Secret Tokens

After reading Code Climate's Rails' Insecure Defaults I realized I was guilty of breaking rule 3. Versioned Secret Tokens. Here's how I fixed it.

Use dotenv in development and test environments:

# Gemfile
gem 'dotenv-rails', groups: [:development, :test]