Skip to content

Instantly share code, notes, and snippets.

View hrp's full-sized avatar

Hiten Parmar hrp

View GitHub Profile
@hrp
hrp / swizzin-proxmox.md
Last active August 12, 2023 20:50
Swizzin install with Proxmox

Swizzin install with Proxmox

Unprivileged container with local bind mount.

  1. Create container with Ubuntu 22.04 LTS
  2. Install Swizzin with script. Note user created.
  3. On Proxmox host, create group for container-data for unused group id (used 101001)
addgroup --gid 101001 container-data
@hrp
hrp / twitter.json
Created April 4, 2011 00:20
Example JSON response from Twitter streaming API
{
"text": "RT @PostGradProblem: In preparation for the NFL lockout, I will be spending twice as much time analyzing my fantasy baseball team during ...",
"truncated": true,
"in_reply_to_user_id": null,
"in_reply_to_status_id": null,
"favorited": false,
"source": "<a href=\"http://twitter.com/\" rel=\"nofollow\">Twitter for iPhone</a>",
"in_reply_to_screen_name": null,
"in_reply_to_status_id_str": null,
"id_str": "54691802283900928",
#!/usr/bin/ruby
require 'benchmark'
puts "Running Ruby #{RUBY_VERSION}"
ary = []
200.times {
ary << {:bar => Time.at(rand * Time.now.to_i)}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hrp
hrp / case-insensitive-include.rb
Created December 28, 2013 01:29
Case insensitive String#include? benchmark
marking answers to http://stackoverflow.com/questions/9333952/in-ruby-how-to-make-the-string-include-method-ignore-case/9334066
# http://www.gutenberg.org/cache/epub/1661/pg1661.txt
strings = IO.read('sherlock.txt').scan(/\w+/) # 109,222 words
known = 500.times.map do
strings.sample.downcase.chars.map{ |c| rand<0.5 ? c.upcase : c }.join
end
words = known.flat_map{ |s| [s, s+"-"] } # \w does not include -
@hrp
hrp / acts-as-taggable-speed.rb
Last active January 3, 2016 03:59
acts-as-taggable-on speed hack
module ActsAsTaggableOn
mattr_accessor :ignore_case_for_mysql
@@ignore_case_for_mysql = false
class Tag
class << self
def named_any_with_ignore_case(list)
if ActsAsTaggableOn.ignore_case_for_mysql
where(list.map { |tag| sanitize_sql(["name = ?", tag.to_s.mb_chars.downcase]) }.join(" OR "))
else
@hrp
hrp / no-ascii.rb
Created December 28, 2013 01:36
Dump non-ascii benchmark
# encoding: utf-8
require 'benchmark'
require 'iconv'
class String
def remove_nonascii(replacement='')
n=self.split("")
self.slice!(0..self.size)
@hrp
hrp / gitconfig
Created December 28, 2013 01:01
gitconfig
[alias]
co = checkout
st = status
br = branch
ci = commit
cm = commit -m
cia = commit -a
lg = log -p
df = diff
dc = diff --cached
build_package_combined_patch() {
local package_name="$1"
{
curl https://raw.github.com/skaes/rvm-patchsets/master/patchsets/ruby/1.9.3/p448/railsexpress | xargs -I % curl https://raw.github.com/skaes/rvm-patchsets/master/patches/ruby/1.9.3/p448/% | patch -p1
autoconf
./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 8
make install
} >&4 2>&1