Skip to content

Instantly share code, notes, and snippets.

View sergiks's full-sized avatar

Sergei Sokolov sergiks

  • Russia | Europe | Thailand
View GitHub Profile
@sergiks
sergiks / reset_file_associations.sh
Created February 13, 2018 20:52
OS X reset of file associations with apps used to open them
# Source: https://superuser.com/questions/640730/mac-os-x-file-associations-keep-changing-though-reverting-it-manually
# Delete LaunchServices prefs:
rm ~/Library/Preferences/com.apple.LaunchServices.plist
# Rebuild the Launch Services database with
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user
@sergiks
sergiks / naiveBayes.py
Created October 25, 2017 19:56
Naive Bayes attempt to classify boolean data
"""
Feature is 512 1-s or 0-s, label is 1 or 0
Data represents some bio research on components added to a mixture,
all are independant one from another.
Outcome is passing some threshold for a further research.
"""
import numpy as np
from sklearn.naive_bayes import GaussianNB
@sergiks
sergiks / commands.sh
Created August 24, 2017 08:10
Useful Linux commands
#!/bin/bash
# This will dump a list of every directory on the filesystem prefixed with
# the number of files (and subdirectories) in that directory.
# Thus the directory with the largest number of files will be at the bottom.
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
# Source: https://unix.stackexchange.com/questions/117093/find-where-inodes-are-being-used
@sergiks
sergiks / console.js
Last active June 9, 2017 12:44
VK send message via browser console JS
/**
* Отправка ЛС во ВКонтакте скриптом из консоли браузера.
* Эксперимент для валидации идеи с Electron-приложением.
* Работает 2017-06-09 в Firefox 53.0.3 (64-bit) / Mac OS X 10.11.6
*
* Выполнять на странице диалога с нужным пользователем
* https://vk.com/im?sel=755074 цифры в конце это id пользователя ВК.
*
* by Sergei Sokolov, hello@sergeisokolov.com, 2017-06-09, Moscow.
*/
@sergiks
sergiks / vkscript.php
Last active December 3, 2017 09:51
calling VKScript
<?php
$params = array(
'code' => " говнокод here ",
'access_token' => $token,
'v' => 5.64,
);
$url = 'https://api.vk.com/method/execute'. '?' . http_build_query( $params);
@sergiks
sergiks / zigzag.js
Created April 8, 2017 16:01
Rail Fence (zigzag) cipher JavaScript implementation
/**
* Rail Fence (zigzag) cipher JavaScript implementation.
* https://en.wikipedia.org/wiki/Rail_fence_cipher
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
@sergiks
sergiks / NumText.php
Created March 12, 2017 09:08
PHP class for convertion between Russian text and numbers. First draft.
<?php
/**
* Перевод численных в числа и чисел в текст на Русском языке.
*
* Сергей Соколов hello@sergeisokolov.com Москва 2017.
*/
class NumText {
@sergiks
sergiks / apps-centrum-sum.min.js
Created February 8, 2017 08:53
Букмарклет для подсчёта выплат за месяц на AppsCentrum (минифицирован)
(function(t){var e,n,a,h=$("table"),r={},o=new Date,l="";if(!("my.appscentrum.com"!=window.location.hostname||h.length<4)){for(o.setDate(1),a=0;t>a;a++)e=("0"+(parseInt(o.getMonth())+1)).substr(-2),n=""+o.getFullYear(),r[""+e+"."+n]=0,o.setMonth(o.getMonth()-1);h=h[3],$("tr",h).each(function(t,e){var n,a,h=$("td:nth-child(5)",this).text().split(/[\ \.]/);h.length>=2&&(a=""+h[1]+"."+h[2],r.hasOwnProperty(a)&&(n=$("td:nth-child(3)",this).text(),(n=n.replace(/[^0-9\.]+/g,"")).length&&(r[a]+=parseFloat(n))))});for(key in r)l+=""+Math.round(100*r[key])/100+" руб. за "+key+"\r\n";alert(l)}})(5);
@sergiks
sergiks / apps-centrum-sum.js
Created February 8, 2017 08:44
Букмарклет для подсчёта выплат за месяц на AppsCentrum (несжатый код)
/**
* Bookmarklet for my.appscentrum.com
* to display agregated payouts by month
* for the last 3 months.
*
* Minify with command:
*
* uglifyjs -m -c negate-iife=false apps-centrum-sum.js
*
* by Sergei Sokolov hello@sergeisokolov.com
#!/bin/bash
#
# Backup database and files of a Wordpress blog running in a Docker container
#
# by Sergei Sokolov hello@sergeisokolov.com
# Moscow, 2016 September 08
#
DC_MYSQL=dockerwp_mysql_1