Skip to content

Instantly share code, notes, and snippets.

@alepez
alepez / ssh-stupid-ntp.sh
Created June 30, 2015 12:54
set datetime taken from remote via ssh (when ntp isn't available)
sudo date -s "$( ssh user@host 'date "+%Y-%m-%d %H:%M:%S"' )"; sudo hwclock --systohc
@alepez
alepez / LiveReloadMake.py
Last active August 29, 2015 14:22
LiveReloadMake - LiveReload Make extension for Sublime Text 3
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import threading
import subprocess
import sys
import sublime
import sublime_plugin
@alepez
alepez / LiveReloadMake.py
Created June 4, 2015 15:17
LiveReloadMake
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import threading
import subprocess
import sys
import sublime
import sublime_plugin
@alepez
alepez / selectmenu-blur-event.js
Created May 22, 2015 14:23
selectmenu blur event
// You can access the `focusable` element of selectmenu instance:
$('SELECTOR').selectmenu('instance').focusable.blur(function() {
// this is executed when selectmenu looses focus
});
@alepez
alepez / hexencode.cpp
Created May 13, 2015 09:54
hex encode
#include <string>
#include <vector>
#include <iostream>
using byte = uint8_t;
static std::string hexEncode(const std::vector<uint8_t>& data) {
std::string result(data.size() * 3, ' ');
for (size_t i = 0, k = 0; k < result.size(); ++i, k += 3) {
static const char hex[] = "0123456789abcdef";
@alepez
alepez / ipv4_sockaddr_to_human_readable_ip.cpp
Created May 12, 2015 15:48
ipv4 sockaddr to human readable ip
#include <netdb.h>
#include <arpa/inet.h>
#include <iostream>
#include <cstring>
#include <stdexcept>
int main(int argc, char* argv[]) {
if (argc < 2) {
return 0;
}
@alepez
alepez / busybox-date-operations.sh
Created March 30, 2015 09:55
busybox date timestamp 1 hour ago
echo "$(( $( date +%s ) - 3600 ))"
@alepez
alepez / automatic-test.js
Created March 21, 2015 16:22
automati javascript test
/*==============================================================================
= Automatic test runner. Add tests below =
==============================================================================*/
$(function () {
/*========== Test runner ==========*/
var Test = function () {
var that = {},
actions = [],
index = -1, elapsedTime = 0;
@alepez
alepez / call-function-only-if-defined.js
Created March 19, 2015 16:43
call function only if exists
(this.props.onChange || Function)();
@alepez
alepez / local-storage-value-handler.js
Created February 28, 2015 10:28
local storage value handler
var permanentValue = function (name) {
var that = {};
var prefix = 'debug-';
that.store = function (val) {
localStorage.setItem(prefix + name, val);
return val;
};
that.load = function () {
return localStorage.getItem(prefix + name);
};