Skip to content

Instantly share code, notes, and snippets.

View atzkey's full-sized avatar
💾
Softly bytes.

atzkey

💾
Softly bytes.
View GitHub Profile
@atzkey
atzkey / smoothen.rb
Created March 24, 2020 18:45
Theorem screening question
# An idiomatic Ruby mixin to Array-like classes.
module ArrayX
# A re-implementation of the native `Array#flatten` method.
# Returns a one-dimensional flattened version of `self`,
# or flattens it to a degree, specified by `level`.
#
# @param level [Number] level of recursion
# @return [Array] flattened array
def smoothen(level = -1)
return self if level == 0
@atzkey
atzkey / wtf.rb
Created October 22, 2015 08:00
Random WTF
% % % == %
%= = % % == %
# Hint:
%%%===%==
@atzkey
atzkey / tutby_nocopy.js
Last active October 2, 2015 16:57
tut.by nocopy user script
// ==UserScript==
// @name tut.by nocopy
// @namespace http://atzkey.org/
// @version 0.1
// @description Removes the "Full article" link from the copied article text
// @author atzkey
// @match http*://*.tut.by/*
// @grant none
// ==/UserScript==
#!/usr/bin/env bash
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Add extensions to check here
puts *['()',*0.step(15,2).map{|i|'/'+('* '*3+' '*i)[0,i].scan(/../).shuffle*''+'\\'},'[]'].map{|t|t.center(16)}
@atzkey
atzkey / gist:1147109
Created August 15, 2011 16:24
Shoulda context that allows stubbing of constants
def context_with_constants(name, object, constants, &block)
object ||= Object
context "#{name} with constants #{constants.inspect}" do
setup do
@saved_constants = {}
constants.each do |k, v|
@saved_constants[k] = object.const_get(k)
Kernel::silence_warnings { object.const_set(k, v) }
end
@atzkey
atzkey / gist:1122563
Created August 3, 2011 12:55
assert_url_has_param
##
# Passes if +url+ contains +param+ in its query string.
#
# Example:
# assert_url_has_param("http://google.com/?q=RTFM", 'q=RTFM')
def assert_url_has_param(url, param, message = nil)
message = build_message message, "<?> does not contain param <?>", url, param
assert_block message do
URI.parse(url).query.split('&').any?{|p| p == param}
end
@atzkey
atzkey / string.format.js
Created December 13, 2010 15:58
String.format extension for JavaScript
/*
String.format extension for JavaScript
Next line should give you an idea how to use it:
"{1}, {0}!".format("world", "Hello");
*/
String.prototype.format = function() {
var formatted = this;
for (arg in arguments) {
/*
jQuery UI Autocomplete AutoFill extension
automatically fills in the input box when only one suggestion is to be shown
*/
;(function($) {
$.extend($.ui.autocomplete.options, {autoFill: true});
$.extend($.ui.autocomplete.prototype, {
_response_original: $.ui.autocomplete.prototype._response,
/* Routine that generates frequencies for all 128 MIDI notes */
#include <stdio.h>
#include <math.h>
int main()
{
float midi[127];
int a = 440; // a is 440 hz...
int x;