Skip to content

Instantly share code, notes, and snippets.

@teramako
teramako / bartab-integration.js
Created April 26, 2010 13:32
BarTab integration - Vimperator Plugin
/*
* BarTab integration - Vimperator Plugin
*
* Commands:
* :tap tap the current tab
* :tap # tap the previous seleced tab
* :tap {num}:? tap the {num}-th tab
* :tap! tap all tabs without the current tab
*
* Tab Completion is available !!
@nas
nas / gbgrep
Created May 20, 2011 18:19
git blame with grep
#!/usr/local/bin/ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
puts "\n-----------------------------------------------------------"
puts "GREP RESULT"
puts '-----------------------------------------------------------'
puts grep
files = grep.scan /.*\:\d+/
@mrdziuban
mrdziuban / PsySH_with_Yii.md
Last active August 21, 2019 10:20
How to use PsySH with a Yii application

Using PsySH (GitHub) as the Yii shell

  • Issue the following commands from the command line in your Yii application directory:
    • chmod +x shell
    • mkdir extensions/yiishell
    • wget -O extensions/yiishell/psysh psysh.org/psysh
    • chmod +x extensions/yiishell/psysh
  • Copy the file init.php below to extensions/yiishell/init.php and update any paths to work with your application configuration
  • Copy the file config.php below to extensions/yiishell/config.php. Change or add to the config array with the options you'd like to use (available options)
  • Now you can start PsySH with the command extensions/yiishell/psysh extensions/yiishell/init.php --config extensions/yiishell/config.php
<?php
namespace Roots\Sage\Nav;
use Roots\Sage\Utils;
/**
* Cleaner walker for wp_nav_menu()
*
* Walker_Nav_Menu (WordPress default) example output:
@theoretick
theoretick / ruby_tap_in_elixir.ex
Last active January 23, 2020 05:56
ruby #tap in elixir
iex(1)> defmodule Util do
...(1)> def tap(input, func) do
...(1)> func.(input)
...(1)> input
...(1)> end
...(1)> end
{:module, Util,
<<70, 79, 82, 49, 0, 0, 4, 212, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 164, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>,
{:tap, 2}}
iex(2)> import Util
defmodule Parser do
@moduledoc """
Sample parser for article on:
http://stefan.lapers.be/posts/elixir-writing-an-expression-parser-with-nimble-parsec/
"""
import NimbleParsec
not_ = string("!") |> label("!")
and_ = string("&&") |> replace(:&&) |> label("&&")
or_ = string("||") |> replace(:||) |> label("||")
@slashdotdash
slashdotdash / upsert_profile.ex
Last active July 26, 2020 23:09
Upserts in Ecto using `Ecto.Multi`
defp upsert_profile(multi, source, source_uuid, profile_url) do
profile = %Profile{
source: source,
source_uuid: source_uuid,
profile: profile_url,
}
Ecto.Multi.insert(multi, source_uuid, profile, on_conflict: [set: [profile: profile_url]], conflict_target: [:source, :source_uuid])
end
@haf
haf / gist:2843680
Created May 31, 2012 14:19
Get SSH working on Vagrant/Windows/Git

If you are using vagrant, you probably-statistically are using git. Make sure you have its binary folder on your path, because that path contains 'ssh.exe'.

Now, modify C:\vagrant\vagrant\embedded\lib\ruby\gems\1.9.1\gems\vagrant-1.0.3\lib\vagrant\ssh.rb to comment out the faulty Windows check and add a real SSH check:

# if Util::Platform.windows?
  # raise Errors::SSHUnavailableWindows, :host => ssh_info[:host],
                                       # :port => ssh_info[:port],
                                       # :username => ssh_info[:username],
 # :key_path =&gt; ssh_info[:private_key_path]
@jbowens
jbowens / ListCodeDefinition.php
Last active April 9, 2021 09:06
A [list] BBCode definition for jBBCode using [*] for list items.
<?php
require_once "jBBCode" . DIRECTORY_SEPARATOR . "Parser.php";
/**
* Implements a [list] code definition that provides the following syntax:
*
* [list]
* [*] first item
* [*] second item
@ZJONSSON
ZJONSSON / force_labels.js
Last active May 18, 2023 08:52
Automatic floating labels using d3 force-layout
(function() {
d3.force_labels = function force_labels() {
var labels = d3.layout.force();
// Update the position of the anchor based on the center of bounding box
function updateAnchor() {
if (!labels.selection) return;
labels.selection.each(function(d) {
var bbox = this.getBBox(),
x = bbox.x + bbox.width / 2,