Skip to content

Instantly share code, notes, and snippets.

View kwilczynski's full-sized avatar
🐧

Krzysztof Wilczyński kwilczynski

🐧
  • Yokohama, Japan
  • 14:22 (UTC +09:00)
View GitHub Profile
@kwilczynski
kwilczynski / example.rb
Last active March 21, 2021 21:35
Numeric#to_human_readable in Ruby
class Numeric
def to_human_readable
suffixes = %w(B kB MB GB TB PB EB)
begin
index = (Math.log(self) / Math.log(1024)).to_i
rescue Errno::ERANGE
index = 0
end
krzysztof@samsung:~$ cat > test.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i;
int *p = &i;
printf("0x%08x\n", (unsigned int) p);
diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
index e2c83a2..a5b24ed 100644
--- a/drivers/isdn/hardware/mISDN/hfcpci.c
+++ b/drivers/isdn/hardware/mISDN/hfcpci.c
@@ -2294,7 +2294,7 @@ _hfcpci_softirq(struct device *dev, void *arg)
struct hfc_pci *hc = dev_get_drvdata(dev);
struct bchannel *bch;
if (hc == NULL)
- return 0;
+ return -ENODEV;
@jfarmer
jfarmer / 01-truthy-and-falsey-ruby.md
Last active March 5, 2025 10:26
True and False vs. "Truthy" and "Falsey" (or "Falsy") in Ruby, Python, and JavaScript

true and false vs. "truthy" and "falsey" (or "falsy") in Ruby, Python, and JavaScript

Many programming languages, including Ruby, have native boolean (true and false) data types. In Ruby they're called true and false. In Python, for example, they're written as True and False. But oftentimes we want to use a non-boolean value (integers, strings, arrays, etc.) in a boolean context (if statement, &&, ||, etc.).

This outlines how this works in Ruby, with some basic examples from Python and JavaScript, too. The idea is much more general than any of these specific languages, though. It's really a question of how the people designing a programming language wants booleans and conditionals to work.

If you want to use or share this material, please see the license file, below.

Update

@dstroot
dstroot / performance.txt
Created May 25, 2012 01:27
Performance Tuning your TCP Stack
#!/bin/bash
echo "*****************************************"
echo " Based on information from Google"
echo " http://dev.chromium.org/spdy/spdy-best-practices"
echo "*****************************************"
sudo su
yum –y update
echo "*****************************************"
echo " Changing initcwnd and initrwnd"
echo " Step 1: check route settings."
@ammar
ammar / ruby_wrappers.c
Created May 25, 2012 10:23
Examples of wrapping rb_funcall and rb_funcall2 with rb_rescue2.
#define MY_FUNCALL_ARGC 3
VALUE my_funcall(VALUE receiver, ID method_id, int argc, ...);
VALUE my_funcall_ex(VALUE data);
VALUE my_funcall2(VALUE receiver, ID method_id, int argc, VALUE *argv);
VALUE my_funcall2_ex(VALUE data);
// my_rescue: exception handler used by both of the wrappers below.
@frsyuki
frsyuki / my_thoughts_on_msgpack.md
Created June 11, 2012 02:36
My thoughts on MessagePack

My thoughts on MessagePack

Hi. My name is Sadayuki "Sada" Furuhashi. I am the author of the MessagePack serialization format as well as its implementation in C/C++/Ruby.

Recently, MessagePack made it to the front page of Hacker News with this blog entry by Olaf, the creator of the Facebook game ZeroPilot. In the comment thread, there were several criticisms for the blog post as well as MessagePack itself, and I thought this was a good opportunity for me to address the questions and share my thoughts.

My high-level response to the comments

To the best of my understanding, roughly speaking, the criticisms fell into the following two categories.

@marktheunissen
marktheunissen / pedantically_commented_playbook.yml
Last active August 25, 2025 12:52 — forked from phred/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
This playbook has been removed as it is now very outdated.
Facter.add(:guests) do
confine :virtual => 'physical', :has_libvirtd => 'true'
setcode do
begin
require 'libvirt'
rescue LoadError
require 'rubygems'
require 'libvirt'
end
@tetsuok
tetsuok / .gdbinit
Created June 30, 2012 20:16
Turning off optimization and inlining in Go gc compilers for debugging.
source /usr/local/go/src/pkg/runtime/runtime-gdb.py
b main.main