Skip to content

Instantly share code, notes, and snippets.

@atika
atika / generate_nginx_vhosts_puphpet.php
Last active January 15, 2016 12:36
Generate Vagrant/PuPHPet Nginx vhosts configuration for multiples sites
<?php
$websites = [
["uid" => "mywebsite01", "name" => "mywebsite01.dev", "alias"=>"www.mywebsite01.dev", "root" => "/var/www/mywebsite01/www"],
["uid" => "mywebsite02", "name" => "mywebsite02.dev", "alias"=>"", "root" => "/var/www/mywebsite02/www"]
];
$template =
" nxv__UID_:
@atika
atika / FloatToDecimalStringExtension.swift
Last active March 10, 2016 09:50
Format a float value with desired numbers after the comma to a string. Doesn't display the comma if the number is a round value.
// Format a float value with desired numbers after the comma to a string. Doesn't display the comma if the number is a round value.
import Foundation
extension Double {
func toDecimalString(decimals: Int = 0) -> String {
let format = (self % 1 > 0 && decimals > 0) ? "%.\(decimals)f" : "%.0f"
return String(format:format, self)
}
@atika
atika / RemapValueToAnotherRange.swift
Created March 10, 2016 10:10
Remap/Convert a value from one range to another range (graph) in Swift
let high1 = 1000
let low1 = 200
let high2 = 250
let low2 = 10
let value = 200
let remapedValue = low2 + (value - low1) * (high2 - low2) / (high1 - low1)
@atika
atika / alias_stats.txt
Last active April 9, 2016 14:56
Statistics of shell aliases usage and optional search for a specific command (change to .bash_history for Bash Shell)
alias_stats() {
local search="$1"
list=""; for c in $(alias | grep "$search" | cut -d'=' -f1); do count=$(grep -Ec ";$c" ~/.zsh_history); list="${list}\n${count} ${c}"; done; echo -e $list | sort -n | grep -Ev "^0"
}
@atika
atika / bash_profile.sh
Last active May 31, 2018 22:36
Some useful Shell aliases and functions for using on Mac OS X. Compatible with Bash/Zsh shells.
# Some useful Shell aliases and function for using on Mac OS X
# https://gist.github.com/atika/4bca2820b21a71858a06
# Regular Expressions
ipregx="[0-9]{2,3}\.[0-9]{2,3}\.[0-9]{2,3}\.[0-9]{2,3}" # IP Regular Expression
mailregx="[a-zA-Z0-9_-\.]+@[a-zA-Z0-9_-\.]+\.[a-z]{2,3}" # Mail Regular Expression
# ql : Show a "Quick Look" view of files
ql () { /usr/bin/qlmanage -p "$@" >& /dev/null & }
@atika
atika / NSTimeZoneTest.swift
Created March 10, 2016 09:59
NSTimeZone tests and change app default TimeZone in Swift
let tz = NSTimeZone.init(forSecondsFromGMT:3600)
NSTimeZone.setDefaultTimeZone(tz) // Change app default timezone
print(tz) // GMT+0100 (UTC+1) offset 3600
print(NSDate()) // 2016-03-10 09:57:44 +0000
print(tz.abbreviation) // Optional("UTC+1")
print(tz.name) // GMT+0100
print(tz.description) // GMT+0100 (UTC+1) offset 3600
@atika
atika / CodeRunner-AngularJS-Exemple.js
Created March 10, 2016 10:58
CodeRunner compilation script to have Javascript, HTML and CSS in the same file
// The first script tag is optional if you start with javascript
//<script>
$(document).ready(function () {
$("body").append("<br>jQuery said AngularJS rocks!");
alert($(document).html());
});
angular.module('PricesApp', [])
.controller("PriceController", function () {
@atika
atika / marked-markdown-preprocessor.rb
Last active September 29, 2018 03:40
Use Marked 2 markdown preprocessor functionality to rewrite each image URL to an absolute path on the system before displaying the preview.
#!/usr/bin/ruby
require 'pathname'
imgURLRegex = /^(!\[.*?\]\()([^\s\)]*)(\s*.*\))/
rootsPaths = [
'/Users/username/Path/To/hexo/source/',
'/Another/PathTo/Website/Directory/'
]
@atika
atika / osx_set_app_category.sh
Last active September 29, 2018 03:40
Set the missing app category on OS X
#!/bin/bash
# Write category for an app
developer="public.app-category.developer-tools"
utilities="public.app-category.utilities"
productivity="public.app-category.productivity"
photography="public.app-category.photography"
video="public.app-category.video"
music="public.app-category.music"
@atika
atika / verify_programs.sh
Last active October 22, 2018 04:19
Verify if programs exits on system before executing a shell script
verify_programs() {
local programs="$1"
local ccyan="\\033[1;36m"
local cnormal="\\0033[0;39m"
abort=0
for p in $programs; do
type $p >/dev/null 2>&1 || { echo -e >&2 " ${ccyan}${p}${cnormal} required but it's not installed. Aborting."; abort=1; }
done
if [[ $abort -eq 1 ]]; then
exit 1;