Skip to content

Instantly share code, notes, and snippets.

Avatar

Simone Carletti weppos

View GitHub Profile
View console.log
➜ publicsuffix-go git:(master) ✗ cd ~/go/src/golang.org/x/net/idna; git co 69d4b8; cd -; go run idna-test.go
Note: checking out '69d4b8'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
@weppos
weppos / git-prs.md
Created Mar 28, 2016
PRs as Git Branches
View git-prs.md

If you want to download GitHub PRs to your local repository, you can use a little trick to download them as local branches.

Open the repository configuration file (.git/config) and search for the origin block. Change it from:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:USERNAME/REPOSITORY.git
@weppos
weppos / 44.go
Last active Mar 22, 2021
A Tour of Go Exercise: Fibonacci closure
View 44.go
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
f2, f1 := 0, 1
return func() int {
f := f2
View compression-gzip.conf
# Enables compression for everything except compressed images.
# See http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
# Required mod_deflate and mod_headers
<IfModule mod_deflate.c>
<IfModule mod_headers.c>
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
@weppos
weppos / capistrano_database_yml.rb
Created Jul 27, 2008
Provides a couple of tasks for creating the database.yml configuration file dynamically when deploy:setup is run.
View capistrano_database_yml.rb
#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category:: Capistrano
# Package:: Database
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2010 The Authors
View preferred_version_redirect.rb
class PreferredVersionRedirect
def initialize(app)
@app = app
end
def call(env)
req = Rack::Request.new(env)
if valid?(req)
@app.call(env)
View routes.rb
Rails.application.routes.draw do
# pre
constraints(host: %r{www\.example\.com}) do
get '/', to: redirect('https://example.com')
get '/*path', to: redirect { |params, _| "https://example.com/#{params[:path]}" }
end
# post
View gist:3411eafc2c52e69ec751
Rehearsal -----------------------------------------
lib: 0.560000 0.000000 0.560000 ( 0.565598)
own: 0.640000 0.010000 0.650000 ( 0.651338)
-------------------------------- total: 1.210000sec
user system total real
lib: 0.650000 0.000000 0.650000 ( 0.666613)
own: 0.650000 0.010000 0.660000 ( 0.651895)
View matcher.go
package main
import (
"fmt"
"io/ioutil"
"os/exec"
"strings"
)
func opensslModulus(command string, content string) (string, error) {
@weppos
weppos / fliwn.rb
Created Dec 6, 2012
Script to download a Flickr photoset.
View fliwn.rb
#!/usr/bin/env ruby -wKU
require 'rubygems'
require 'flickraw'
require 'open-uri'
require 'fileutils'
FlickRaw.api_key = "YOUR_API_KEY"
FlickRaw.shared_secret = "YOUR_SHARED_SECRET"