Skip to content

Instantly share code, notes, and snippets.

View ofstudio's full-sized avatar

Oleg Fomin ofstudio

View GitHub Profile
@ofstudio
ofstudio / defer-promise.js
Last active August 29, 2015 14:02
Javascript Deferred / Promise pattern
/**
* A simple workaround on Deferred / Promise pattern
* with result caching and multiply actions on success / fail
*
* defer() returns methods:
* resolve(data) - request is successfully resolved (returns nothing)
* reject(msg) - request if failed (returns nothing)
* promise() - returns promise function
*
* promise() returns methods:
@ofstudio
ofstudio / ieVersion.js
Created June 16, 2014 19:02
ieVersion.js - returns version of Internet Explorer
/**
*
* Returns the version of Internet Explorer
* or undefined if no Internet Explorer detected
* Tested in IE8 ... IE11
*
* http://stackoverflow.com/a/20815285/3071651
*
*/
function ieVersion () {
@ofstudio
ofstudio / djay2itunes.scpt
Last active August 29, 2015 14:03
Copy BPMs and Keys calculated in Algoriddim djay for Mac to iTunes meta tags
(*
** THIS SCRIPT IS OUTDATED **
Check https://github.com/ofstudio/djay2itunes.js for new version
djay2itunes.scpt
Description: Copy BPMs and Keys calculated in Algoriddim djay for Mac to iTunes meta tags
Version: 0.0.1 / July 2014
@ofstudio
ofstudio / get_password.sh
Created December 14, 2014 16:39
Get password from OS X Keychain shell / bash function
# Get password from OS X Keychain function
# Replace %ACCOUNT_NAME% with account name of Keychain item
# See `man security` for more info
get_pw () {
security 2>&1 >/dev/null find-generic-password -ga "%ACCOUNT_NAME%" \
| sed 's/password: "\(.*\)"/\1/'
}
# Don't store server credentials in plain text!
PASS=$(get_pw)
@ofstudio
ofstudio / OSAjs-file-folder-exists.js
Created December 28, 2014 11:58
Example of file / folders scripting in OS X with Javascript
/**
* Example of file / folders scripting in OS X with Javascript
* Open /Applications/Script Editor.app, paste the code and click Run button
*
* @author Oleg Fomin <ofstudio@gmail.com>
*
*/
function file_exists(name) {
try {
@ofstudio
ofstudio / OSAjs-dialogs.js
Last active August 29, 2015 14:12
Example of dialogs / notifications scripting in OS X with Javascript
/**
* Example of dialogs / notifications scripting in OS X with Javascript
* Open /Applications/Script Editor.app, paste the code and click Run button
*
* @author Oleg Fomin <ofstudio@gmail.com>
*
*/
var result,
my_app = Application.currentApplication();
@ofstudio
ofstudio / OSAjs-itunes.js
Created December 28, 2014 12:01
Example of iTunes scripting in OS X with Javascript
/**
* Example of iTunes scripting in OS X with Javascript
* Open /Applications/Script Editor.app, paste the code and click Run button
*
* @author Oleg Fomin <ofstudio@gmail.com>
*
*/
var my_app = Application.currentApplication(),
itunes = new Application('iTunes'),
@ofstudio
ofstudio / meta.hbs
Created January 6, 2015 13:43
Meta tags snippet for Ghost Themes
{{!-- Tested on Ghost 0.5.7. --}}
{{!-- IMPORTANT! Some things are more likely to work in a different way in future versions of Ghost. Check the documentation --}}
{{#is "index, tag, author"}} {{!-- Meta for index, tag and author contexts --}}
{{#is "index"}}
<title>{{@blog.title}}</title>
<meta name="description" content="{{@blog.description}}"/>
<meta property="og:title" content="{{@blog.title}}"/>
<meta itemprop="name" content="{{@blog.title}}"/>
{{/is}}
{{#is "tag"}}
@ofstudio
ofstudio / DCevent simple translit example
Created January 14, 2015 15:41
Транслитерация для DCevent.js
<!-- Скрипт транслитерации -->
<script>
function translate(str) {
function strtr(s, replacePairs) {
"use strict";
var str = s.toString(), key, re;
for (key in replacePairs) {
if (replacePairs.hasOwnProperty(key)) {
re = new RegExp(key, "g");
@ofstudio
ofstudio / ghost-post-by-tags.js
Last active August 29, 2015 14:14
Ghost browse posts by tag snippet
var api = require('ghost/core/server/api');
api.posts.browse({
context: {
internal: true
},
tag: 'music'
}).then(function (responce){
console.log(responce);
});