Skip to content

Instantly share code, notes, and snippets.

@aizatto
aizatto / gist:1224927
Created September 18, 2011 09:54
jQuery UI Datepicker - Modify another datepicker based on the difference of the last value and newly selected value
$('#form_starts_at').datepicker('option', 'onSelect', function(dateText, inst) {
var then = $.datepicker.parseDate(inst.settings.dateFormat, inst.lastVal);
var now = $.datepicker.parseDate(inst.settings.dateFormat, dateText);
var distance = now.getTime() - then.getTime();
var ends_at = $("#form_ends_at").datepicker('getDate')
ends_at.setTime(ends_at.getTime() + distance);
$("#form_ends_at").datepicker('setDate', ends_at);
});
@aizatto
aizatto / deps.php
Created November 7, 2011 10:26
Migrate from Symfony deps to git sumbodules
<?php
function run($command) {
echo $command."\n";
$output = null;
$return_var = null;
exec($command, $ouput, $return_var);
echo $output;
if ($return_var != 0) {
exit($return_var);
/Users/aizat/.phpvm/v5.4.0/bin/phpize
./configure \
--with-php-config=/Users/aizat/.phpvm/v5.4.0/bin/php-config
@aizatto
aizatto / gist:5685299
Created May 31, 2013 14:21
http://tour.golang.org/#57 A Tour of Go Exercise: HTTP Handlers Implement the following types and define ServeHTTP methods on them. Register them to handle specific paths in your web server. type String string type Struct struct { Greeting string Punct string Who string } For example, you should be able to register handlers using: http.Handle("/…
package main
import (
"fmt"
"net/http"
)
type String string
func (s String) ServeHTTP(
@aizatto
aizatto / ConnProxy.go
Last active December 20, 2015 23:09
The best way to learn a protocol is to see the traffic between server and client. But all this is hidden from the user, so I had to find out a way get go to print out the traffic for me.
/**
* The best way to learn a protocol is to see the traffic between server and
* client. But all this is hidden from the user, so I had to find out a way
* get go to print out the traffic for me.
*/
package main
import (
"bufio"
"errors"
@aizatto
aizatto / gist:5685204
Last active August 31, 2016 13:00
http://tour.golang.org/#47 A Tour of Go Advanced Exercise: Complex cube roots Let's explore Go's built-in support for complex numbers via the complex64 and complex128 types. For cube roots, Newton's method amounts to repeating: Find the cube root of 2, just to make sure the algorithm works. There is a Pow function in the math/cmplx package.
package main
import "fmt"
import "math/cmplx"
func Cbrt(x complex128) complex128 {
z := complex128(2)
s := complex128(0)
for {
z = z - (cmplx.Pow(z, 3) - x)/(3 * cmplx.Pow(z, 2))
@aizatto
aizatto / test.sh
Created September 6, 2017 18:28
bash semantic versioning
#!/bin/bash
# test regex
versions=(v1.1.0 v1.2.3 v1.2.3-rc av1.2.3 a1.2.3 v1.2.3-onprem )
for version in "${versions[@]}"
do
if [[ "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo success "$version"
else
echo fail "$version"
@aizatto
aizatto / memory.js
Created September 27, 2017 19:50
allocation memory in node till it runs out
// strict
function mb(bytes) {
return Math.floor(bytes / 1024 / 1024 );
}
function print() {
const memoryUsage = process.memoryUsage();
console.log({
rss: mb(memoryUsage.rss),
heapTotal: mb(memoryUsage.heapTotal),
@aizatto
aizatto / routes.js
Created October 3, 2017 22:44
find out routes express sues
'use strict';
const paths = new Set();
const pathsData = {};
const _ = require('lodash');
function getPath(layer) {
if (layer.route && layer.route.path) {
return layer.route.path;
} else if (layer.path) {
@aizatto
aizatto / webpack.config.js
Created February 5, 2018 00:39
WebPack Config
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const PROD = process.env.NODE_ENV === 'production';
import {
google as googleConfig,
facebook as facebookConfig,