Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Sonique's full-sized avatar

Vitaly Larchenkov Sonique

View GitHub Profile
@Sonique
Sonique / utils.py
Created August 10, 2018 10:49 — forked from jossef/utils.py
python different ways to import external modules (from cdn / memory string / file path / plugin directory)
import imp
import importlib
import inspect
import glob
import requests
import os
def import_from_string(content, module_name, file_name=None):
if not file_name:
file_name = '{0}.py'.format(module_name)
@Sonique
Sonique / hosts.ini
Created July 23, 2018 12:25
Ansible: use any python version for ansible_python_interpreter
[nodes:vars]
ansible_python_interpreter = ls /usr/bin/ | grep -E "^python([2-3](.[0-9])?)?$" | head -n 1
@Sonique
Sonique / executor-shutdown.java
Created April 24, 2017 10:02
Java Executor proper shutdown
try {
System.out.println("attempt to shutdown executor");
executor.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
System.err.println("tasks interrupted");
}
finally {
if (!executor.isTerminated()) {
@Sonique
Sonique / shri.js
Last active August 29, 2015 14:26 — forked from verkholantsev/shri.js
/**
* Реализация API, не изменяйте ее
* @param {string} url
* @param {function} callback
*/
function getData(url, callback) {
var RESPONSES = {
'/countries': [
{name: 'Cameroon', continent: 'Africa'},
{name :'Fiji Islands', continent: 'Oceania'},
# Script dir for script relative path
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
@Sonique
Sonique / 0_reuse_code.js
Last active August 29, 2015 14:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Sonique
Sonique / simple_timer.java
Last active August 29, 2015 14:13
Simple Java code execution timer
// Basic
long start = System.currentTimeMillis();

long end = System.currentTimeMillis();
// Stopwatch
Stopwatch stopwatch = new Stopwatch();
double time = stopwatch.elapsedTime();
// #java #timer #stopwatch
@Sonique
Sonique / git-post-receive-master-to-production-hook.sh
Last active August 29, 2015 14:03
Put files from master branch to production folder
#!/bin/bash
echo "================================="
echo "Post-receive script: START"
WORK_TREE="/site/folder"
GIT_DIR="/home/git/repos/site.git"
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ $branch == "master" ]; then
echo "Branch determined as master."
@Sonique
Sonique / swap_files.sh
Last active July 23, 2018 13:10
Bash: swap files
function swap() { mv $1 $1._tmp; mv $2 $1; mv $1._tmp $2; }
@Sonique
Sonique / gist:7e65abcae021027beabf
Created June 22, 2014 03:20
Laravel .gitignore extended
# System
.DS_Store
Thumbs.db
.Trashes
._*
Icon
.AppleDouble
.LSOverride
# Editors