Skip to content

Instantly share code, notes, and snippets.

@x7c1
x7c1 / TestPrototype.php
Created September 11, 2011 17:11
prototype-based oop in php
<?
include_once 'prototype.php';
use Prototype\Klass;
class TestPrototype extends PHPUnit_Framework_TestCase{
public function test_sample(){
$Person = Klass::create(function($first, $last){
$this->_first = $first;
$this->_last = $last;
@x7c1
x7c1 / NamedParameterTest.php
Created September 12, 2011 16:49
named parameters in php
<?
include_once 'closure.php';
use closure\name;
class NamedParameterTest extends PHPUnit_Framework_TestCase{
public function test_named_parameter(){
$increment = name::parameter(function($x, $y, $z){
return [$x+1, $y+1, $z+1];
});
@x7c1
x7c1 / example.js
Created December 23, 2011 09:23
mixin in javascript
// using node.js
exports.mixin = new function(){
function mixin(klass, trait){
var new_class = function(){};
new_class.prototype = new function(){
var f = function(){}
f.prototype = klass.prototype;
return extend(new f, trait);
};
return new_class;
@x7c1
x7c1 / LDR-Drive.js
Created January 14, 2012 15:38
LDR - Drive (fixed for Chrome)
// original:
// http://userscripts.org/scripts/show/12584
(function(window, load){
if (this.chrome && !load){
var source = '(' + arguments.callee.toString() + ')(this, true);';
var script = document.createElement('script');
script.appendChild(document.createTextNode(source));
document.body.appendChild(script);
@x7c1
x7c1 / gist:3070952
Created July 8, 2012 13:23
cabal inferno
% cabal-dev install && yesod --dev devel
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: yesod-example-0.0.0 (user goal)
trying: warp-1.2.2 (dependency of yesod-example-0.0.0)
trying: lifted-base-0.1.1.1 (dependency of warp-1.2.2)
trying: base-unicode-symbols-0.2.2.4 (dependency of lifted-base-0.1.1.1)
next goal: http-conduit (dependency of yesod-example-0.0.0)
rejecting: http-conduit-1.5.0.2, 1.5.0.1, 1.5.0 (conflict: yesod-example =>
http-conduit>=1.4 && <1.5)
@x7c1
x7c1 / plater_range.php
Created July 17, 2012 16:56
Memory use of a Range class in Plater Library
<?
use x7c1\plater\collection\immutable\Range;
class SampleRangeTest extends \PHPUnit_Framework_TestCase{
public function test_memory(){
foreach(new range(1, 700000) as $i){
//Memory: 2.50Mb
}
}
}
// see also
@x7c1
x7c1 / test_controller.rb
Created August 30, 2012 17:30
Twitter OAuth on Rails
class TestController < ApplicationController
def oauth_consumer
@oauth_consumer ||= OAuth::Consumer.new(
ENV["CONSUMER_KEY"],
ENV["CONSUMER_SECRET"],
:site => "http://twitter.com"
)
end
@x7c1
x7c1 / private.xml
Last active October 10, 2015 23:08
key-mapping by KeyRemap4MacBook
<?xml version="1.0"?>
<root>
<list>
<item>
<name>Kana to Escape</name>
<identifier>private.swap_kana_and_escape</identifier>
<autogen>--KeyToKey-- KeyCode::JIS_KANA, KeyCode::ESCAPE</autogen>
</item>
<item>
<name>Shift to EISUU/KANA</name>
@x7c1
x7c1 / gist:3925312
Created October 21, 2012 00:15
sample to use a script in hatena blog
$(document).ready(function(){
var bye = function(){
alert("bye!");
$("#google_afc_user").css({ height: '0px', overflow: 'hidden' });
}
$("#sample_button").click(bye);
//$("#google_afc_user").css({ display: 'block !important' });
});
// ==UserScript==
// @name damnfullscreen
// @namespace http://x7c1.hatenablog.com/damnfullscreen
// @include http://*.hatenablog.com/*
// ==/UserScript==
(function(window, load){
if (this.chrome && !load){
var source = '(' + arguments.callee.toString() + ')(this, true);';
var script = document.createElement('script');