Skip to content

Instantly share code, notes, and snippets.

Avatar

Vitaly Larchenkov Sonique

  • Russia
View GitHub Profile
@Sonique
Sonique / utils.py
Created Aug 10, 2018 — forked from jossef/utils.py
python different ways to import external modules (from cdn / memory string / file path / plugin directory)
View utils.py
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 Jul 23, 2018
Ansible: use any python version for ansible_python_interpreter
View hosts.ini
[nodes:vars]
ansible_python_interpreter = ls /usr/bin/ | grep -E "^python([2-3](.[0-9])?)?$" | head -n 1
@Sonique
Sonique / executor-shutdown.java
Created Apr 24, 2017
Java Executor proper shutdown
View executor-shutdown.java
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()) {
View 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'},
View gist:edb54e612289edb2b83d
# Script dir for script relative path
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
@Sonique
Sonique / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// 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 Aug 29, 2015
Simple Java code execution timer
View simple_timer.java
// 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 Aug 29, 2015
Put files from master branch to production folder
View git-post-receive-master-to-production-hook.sh
#!/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 Jul 23, 2018
Bash: swap files
View swap_files.sh
function swap() { mv $1 $1._tmp; mv $2 $1; mv $1._tmp $2; }
@Sonique
Sonique / gist:7e65abcae021027beabf
Created Jun 22, 2014
Laravel .gitignore extended
View gist:7e65abcae021027beabf
# System
.DS_Store
Thumbs.db
.Trashes
._*
Icon
.AppleDouble
.LSOverride
# Editors
You can’t perform that action at this time.