Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
snipsnipsnip / uri-http-get.rb
Last active August 24, 2019 15:39
URI::HTTP.get
require 'net/http'
class URI::HTTP
def get(header)
Net::HTTP.start(host, port) do |http|
http.get(request_uri, header)
end
end
end
@snipsnipsnip
snipsnipsnip / zlib-inflate.rb
Last active August 24, 2019 15:41
Zlib.inflate
require 'zlib'
module Zlib
module_function
def inflate(str)
i = Inflate.new(Zlib::MAX_WBITS + 32)
i.inflate str
end
end
@snipsnipsnip
snipsnipsnip / code-list.bat
Created September 2, 2009 16:11
make code list
@ruby -x "%~f0" %*
@exit /b
#!ruby
require 'erb'
if __FILE__ == $0
abort "usage: #{File.basename $0} [code..]" if ARGV.empty?
files = ARGV.map {|glob| Dir.glob(glob) }
files.flatten!
@snipsnipsnip
snipsnipsnip / append_lib_to_path.c
Last active August 24, 2019 15:41
ENV['PATH'] = "#{File.dirname $0}\\lib;#{ENV['PATH']}" in C
#include <windows.h>
#include <stdio.h>
// in ruby: ENV['PATH'] = "#{File.dirname $0}\\lib;#{ENV['PATH']}"
int main(int argc, char **argv)
{
DWORD path_len = GetEnvironmentVariable(TEXT("PATH"), NULL, 0);
char *execpath;
char *last_separator;
TCHAR *path_buf;
@snipsnipsnip
snipsnipsnip / avr_template.c
Last active August 24, 2019 15:41
utility macro for DRY bit / port manipulation
#include <avr/io.h>
// utility macro for DRY bit manipulation
#define ApplyPort(p,n,op) ((p) op _BV(n))
#define Get(pn) ApplyPort(pn,&)
#define Set(pn) ApplyPort(pn,|=)
#define Clear(pn) ApplyPort(pn,&= ~)
#define NOP() __asm("nop")
@snipsnipsnip
snipsnipsnip / launch.c
Last active August 24, 2019 15:41
launcher (relative shortcut replacement)
#include <windows.h>
#define EXECUTABLE_PATH "notepad.exe"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
PROCESS_INFORMATION p;
STARTUPINFO s;
MSG m;
@snipsnipsnip
snipsnipsnip / henkan.rb
Last active August 24, 2019 15:41
henkan.rb
#!ruby -Ks
require 'kconv'
require 'strscan'
class Parser
def initialize(str)
# \201@はSJISでの全角スペース
str = str.gsub("\201@", ' ').gsub(/\/\/.*$/) {|s| ' ' * s.size }.strip
@s = StringScanner.new(str)
@snipsnipsnip
snipsnipsnip / infer.rb
Created October 25, 2009 02:06
infer.rb (what's this? lisp reader??)
require 'strscan'
class Infer
def self.infer(str)
if str.is_a?(String)
tree = Parser.parse(str_or_tree)
else
tree = str_or_tree
end
@snipsnipsnip
snipsnipsnip / eval.js
Last active August 24, 2019 15:41
Mery macro
eval(document.selection.Text)
@snipsnipsnip
snipsnipsnip / eclipse-format.xml
Last active December 6, 2024 19:13
C#-like eclipse code format settings
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="11">
<profile kind="CodeFormatterProfile" name="C#-like" version="11">
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>