Skip to content

Instantly share code, notes, and snippets.

# STEP 1
string = "iirytroyppytpeppowuiyoiuypipiyuyotyoiwiytorouqyiepyirueuiprpptwyiroqwtuyipourrrourorwipowiorutpwtwruuioquteorioriyutwqyyprptuqqquuituyywyuoewtrppqwrtiiruirpwyptpuoyyoeyerpqiotuieripurouwuwyuwrworowitoepoypeipeypiireeorrwripuuteoitpuutturruwiyryeetyrioweytueqrrrtotrpiqetoyepoipiwrwpppiritupwipruooiepoweypiuwrqywuuwyiroqpqpruioopuiuerputpwwuuiqwpiroewrtwiqerteoyeqtutwoeoipioiuqiiiouuoqtuuwtuwiiqwppqitywuqpuutrqiyoeuuutwrwtoqrqyoeyoiporuuioiwryoeruypreprqroiyuqwtuyoytoerwqryeeripryieypiwqirtriurueypiuyuypriuiwptywppupoioyrewooytreteeriiwroietuwypieeeeeqpiiiwrirtppoeyiwpooyyporpruwuoriiyowuytiwpwpryeywotoyirqypyypoeptiuwwoyprquoetepptorwiewprpiywwtuieeiweytrrwiqtwotioryoiptyyyuriiqiyroeeiqepwteuwptpruuypipieuoiiuuweeuryuuowporrooyywyyrryriqyirooitirueruptotpryoqtipippyptiurwyiryooywtryyuurtrutwqiqiiiqwouyeooueoturuowiuwrtruwwiupwopwweoo"
letters = %w(q w e r t y u i o p)
map = {}
letters.each_with_index { |letter, index| map[letter] = index }
numbers = string.split('').map {|letter| map[lette
@stevenyxu
stevenyxu / output
Created February 25, 2012 01:15
Array#uniq in Ruby 1.8.7
~~ [EqualA, EqualB].uniq ~~
EqualA: hash
EqualB: hash
[EqualA, EqualB]
~~ [EqualA, EqualB, EqualC].uniq ~~
EqualA: hash
EqualB: hash
EqualC: hash
[EqualA, EqualB, EqualC]
@stevenyxu
stevenyxu / gist:2363260
Created April 11, 2012 22:43
Preserving "this" inside a function where you can't control the callee
var self = this;
callbackInvoker(function(){
self.doStuff();
});
@stevenyxu
stevenyxu / uniq.rb
Created May 19, 2012 19:15
Print out unique lines in a file
previous = nil
output_buffer = File.open(ARGV[1], 'w')
File.open(ARGV[0], 'r') do |f|
prevline = nil
curline = f.gets
nextline = f.gets
while !curline.nil?
if curline != prevline && curline != nextline
output_buffer.write(curline)
end
@stevenyxu
stevenyxu / gist:3362679
Created August 15, 2012 19:09
Unique keys in MySQL
mysql> show create table foo;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| foo | CREATE TABLE `foo` (
`bar` varchar(128) DEFAULT NULL,
`baz` varchar(128) DEFAULT NULL,
UNIQUE KEY `foo_unique` (`bar`,`baz`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
<!-- application -->
<div class="user">
<span class="name">{{App.user.name}}</span>
</div>
@stevenyxu
stevenyxu / find_pairs.rb
Created November 11, 2013 07:09
Find pairs of numbers in an array that add to 100
# Find pairs that sum to 100
# Input: [13, 2, 14, 3, 13, 97, 13] -> [[3, 97]]
# [1, 99, 1, 99] -> [[1, 99], [1, 99]]
# [50, 50, 50, 50, 50] -> [[50, 50], [50, 50]]
def find_pairs(p_array)
array = p_array.dup
sum = 100
res = []
while first_num = array.shift
Current item schema is up-to-date with version 5ABD0782.
S_StartSound: Failed to load sound 'ui\notification_alert.wav', file probably missing from disk/repository
] ] dota_local_custom_enable 1;dota_local_custom_game Frota;dota_local_custom_map Frota;dota_force_gamemode 15;update_addon_paths;dota_wait_for_players_to_load 0;dota_wait_for_players_to_load_timeout 10;map riverofsouls;Can't change replicated ConVar dota_l
Unknown command "]"
Unknown command "Can"
DrawElement: shader UnlitGeneric doesn't have a snapshot state for drawing
---- Host_NewGame ----
Missing map material: nodraw
TraceRayVerticalGroundHeight() disabled for 'maps/riverofsouls.bsp'
TraceRayVerticalGroundHeight() disabled for 'maps/riverofsouls.bsp'
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('check', function() {
grunt.log.writeln('Checking!');
});
grunt.registerTask('buildFoo', function() {
grunt.log.writeln('Building Foo!');
});
grunt.registerTask('buildBar', function() {
grunt.log.writeln('Building Bar!');
@stevenyxu
stevenyxu / gist:9943182
Created April 2, 2014 21:06
keybase.md
### Keybase proof
I hereby claim:
* I am cairo140 on github.
* I am stevenxuca (https://keybase.io/stevenxuca) on keybase.
* I have a public key whose fingerprint is CDE4 3E21 B230 3957 684E E4AF 6EC2 D557 8079 201C
To claim this, I am signing this object: