Skip to content

Instantly share code, notes, and snippets.

@pachacamac
pachacamac / 2048.rb
Last active August 29, 2015 13:57
2048 game in concise but not golfed Ruby
def rgb(r, g, b)16+(r.to_i*36)+(g.to_i*6)+b.to_i end
def colorize(s, fg, bg = nil) "#{fg ? "\x1b[38;5;#{fg}m" : ''}#{bg ? "\x1b[48;5;#{bg}m" : ''}#{s}\x1b[0m" end
def rainbow(n)f,w,o=5.0/n,3,3; (0...n).map{|i| rgb(Math.sin(f*i+0)*o+w, Math.sin(f*i+2)*o+w, Math.sin(f*i+4)*o+w)} end
def display(board, goal=2048)
@palette ||= rainbow(Math.log2(goal))
puts board.map{|r| r.map{|c| colorize((c==0 ? ?. : c).to_s.center(6), @palette[Math.log2(c+1)])}.join}.join("\n\n")
end
def compress(board, direction)
t=->(a){z=0;a.reduce([]){|s,e| z+=e==s[-1]? (s[-1]+=e;1): e>0? (s<<e;0): 1;s}+Array.new(z,0)} # trivial case: 1D array to the left
require "capybara"
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
sess = Capybara::Session.new(:selenium, app)
sess.visit("/")
__END__
@roge
roge / NT.nut
Created August 24, 2016 13:12
Nade Training v1.0.4-beta by roge. Add file to "Counter-Strike Global Offensive/csgo/scripts/vscripts" then run `script_execute NT.nut` to run.
const NT_TIMER_ENTITY_TARGET_NAME = "NT_TimerEnt";
const NT_SCRIPT_VERSION = "1.0.4-beta";
NT_LastGrenade <- null;
NT_LastRestoredGrenade <- null;
NT_SavedGrenadePosition <- null;
NT_SavedGrenadeVelocity <- null;
NT_AwaitingSave <- false;
NT_IsPaused <- false;
#!/usr/bin/env ruby
# A more general case of finding all of the classes in a hierarchy
#
# Inspired by Nick Sieger's excellent article
# http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy/
#
top_class = Exception
prune_below = [ SystemCallError ]
outer_modules_to_skip = %w[ Gem ]
@codingjester
codingjester / oauth_tumblr.py
Created April 3, 2012 23:33
OAuth Tumblr Getting Access Tokens
import urlparse
import oauth2 as oauth
consumer_key = 'consumer_key'
consumer_secret = 'consumer_secret'
request_token_url = 'http://www.tumblr.com/oauth/request_token'
access_token_url = 'http://www.tumblr.com/oauth/access_token'
authorize_url = 'http://www.tumblr.com/oauth/authorize'
@Nakilon
Nakilon / HOW TO (example).md
Last active March 9, 2021 06:52
streaming a still image with ability to replace it on the fly

Streaming local Moscow time:

  • mkdir stream && cd stream
  • test run:
    docker run --rm -it -v $(pwd):/mounted -w /mounted --log-driver local -e TZ=Europe/Moscow nakilonishe/alpine-vips-text sh -c "apk add tzdata && while sleep 0.5; do vips text image.v \"\$(date '+%Y-%m-%d%n %H:%M:%S')\" --dpi 200 --font Monospace && vips invert image.v atomic.png && mv atomic.png image.png; done"
    export key=...
    docker run --rm -it -v $(pwd):/mounted -w /mounted --log-driver local -e key -e loglevel=info -e s=640x360 -e preset=medium nakilonishe/ffmpeg-stream-image
@Nakilon
Nakilon / checklist.md
Last active May 28, 2021 12:49
new macOS configuration checklist
  • настроить все в System Preferences, например

    • выключить Correct spelling automatically
    • инвертировать кнопку Fn
    • поставить раскладки "США" (на новых макбуках тильды будет слева внизу) и "Русская - ПК"
  • выключить ускорение указателя трекпада и перелогиниться

    defaults write .GlobalPreferences com.apple.trackpad.scaling -1
  • настроить Finder (войти в настройки любой программы в Mac OS можно комбинацией ⌘,)

@tigertv
tigertv / README.md
Created February 16, 2020 23:28 — forked from roachhd/README.md
Games on GitHub

Games on GitHub

Below is a list of open source games and game-related projects that can be found on GitHub - old school text adventures, educational games, 8-bit platform games, browser-based games, indie games, GameJam projects, add-ons/maps/hacks/plugins for commercial games, libraries, frameworks, engines, you name it.

Contributing

If you'd like to add a repository to the list, please create an Issue, or fork this repository and submit a pull request.

Help: MarkDown Help, Markdown Cheatsheet

@rdebath
rdebath / bf.rb
Created September 18, 2015 22:58
Brainfuck interpreter in ruby
eval 'm=Hash.new(p=0);'+ARGF.read.gsub(
/./,
'>' => 'p+=1;',
'<' => 'p-=1;',
'+' => 'm[p]+=1;',
'-' => 'm[p]-=1;',
'[' => '(',
']' => ')while((m[p]&=255)!=0);',
'.' => 'putc m[p];',
',' => 'm[p]=STDIN.getbyte if !STDIN.eof;')
@darkleo
darkleo / chunkypixel_average.rb
Created June 27, 2011 19:17
Pixelizing images with ChunkyPNG
#! usr/bin/env ruby
require 'chunky_png'
class ChunkyPNG::Image
# s: Integer (pixel size)
def pixelize s = 10
temp = Array.new((height*1.0/s).ceil) {Array.new((width*1.0/s).ceil) {Array.new(3) {0}}}
height.times {|j| width.times {|i| ChunkyPNG::Color.to_truecolor_bytes(get_pixel(i,j)).each.with_index {|e,k| temp[j/s][i/s][k] += e}}}
png = ChunkyPNG::Image.new width, height
sq = s**2