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 / gist:1224935
Created September 18, 2011 09:58
PHP Curl Brute Force
<?php
$url = ""; // fill this up
$file = file_get_contents('/usr/share/dict/words');
$words = explode("\n", $file);
$length = count($words);
$multi = curl_multi_init();
$chunks = array_chunk($words, 100);
@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:5684758
Created May 31, 2013 12:50
http://tour.golang.org/#40 A Tour of Go Exercise: Maps Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Test function runs a test suite against the provided function and prints success or failure. You might find strings.Fields helpful.
package main
import (
"strings"
"code.google.com/p/go-tour/wc"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
for _, v := range strings.Fields(s) {
@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 / 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 / deploy.rb
Created June 2, 2017 23:47
Capistrano configuration for yarn
namespace :deploy do
before :updated, 'yarn:install'
before :updated, 'yarn:build'
end
namespace :yarn do
desc 'Install yarn dependencies'
task :install do
@aizatto
aizatto / .bash_profile
Created July 2, 2017 06:20
Display node version in bash prompt
_node_version()
{
local br
br=$(node -v)
test -n "$br" && printf %s "$br" || :
}
green=$'\e[1;32m'
magenta=$'\e[1;35m'
normal_colours=$'\e[m'