Skip to content

Instantly share code, notes, and snippets.

@firstspring1845
firstspring1845 / DespawnMobs.java
Last active August 29, 2015 14:13
敵性モブをデスポーンさせるだけのMOD 1.7.10用のMinecraftForgeで作った
package net.firsp.mods;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.monster.IMob;
@firstspring1845
firstspring1845 / gist:e044bd058513aec85729
Created January 1, 2015 16:32
IntelliJ 正規表現 後方参照
\$N
ex: \[(.*?)\] -> (\$1)
=> [test] -> (test)
@firstspring1845
firstspring1845 / msort.cl
Last active August 29, 2015 14:11
マジなマージ
(defun take (n list)
(if (= n 0) nil (cons (car list) (take (- n 1) (cdr list)))))
(defun slice (n list)
(if (null list) nil (cons (take n list) (slice n (nthcdr n list)))))
(defun msort(list pred)
(cond ((not (consp (car list)))
(msort (slice 1 list) pred))
((equal (cdr list) NIL)
@firstspring1845
firstspring1845 / mergesort.rb
Last active August 29, 2015 14:11
わかる
class Array
def merge(arr)
org = self.reverse
arr = arr.reverse
new = []
loop{
if org == []
return new.concat(arr.reverse)
end
if arr == []
@firstspring1845
firstspring1845 / msort.cl
Last active August 29, 2015 14:11
マージソートに驚いた人「マージで?」
(defun msort (list pred)
(cond ((not (consp (car list)))
(msort (mapcar (lambda (x) (cons x NIL)) list) pred))
((equal (cdr list) NIL)
(car list))
(t
(let (merged)
(loop
(push (merge 'list (pop list) (pop list) pred) merged)
(if (not list) (return (msort merged pred))))))))
@firstspring1845
firstspring1845 / heap.rb
Last active August 29, 2015 14:11
個人用メモ
def downheap!(arr, i, mnode)
a = [i, i*2+1, i*2+2]
b = arr[a[0]]
c = arr[a[1]]
d = a[2] <= mnode ? arr[a[2]] : nil
e = [b,c,d]
e.delete(nil)
f = e.index(e.max)
class Service
def streaming(method = :userstream, *args, &proc)
p = lambda{|q|
if q and not q.empty?
Plugin.call(:json, q) end
proc.call(q)
}
twitter.__send__(method, *args, &p)
end
end
@firstspring1845
firstspring1845 / gist:d56a19812fdb31d69c2c
Created November 17, 2014 09:21
localhost:8000/任意のアドレス?message=ツイート本文
server = WEBrick::HTTPServer.new({:Port => 8000})
server.mount_proc('/'){|req,res|
q = Hash[*(req.query_string.split('&').map{|s|s.split('=')}.flatten)]
if q.include?('message')
Service.primary.post(:message => q['message'])
end
}
Thread.new{server.start}
import random
f = open('a.bmp','rb').read()
f = list(f)
for i in range(0x36, len(f)):
if random.random() < 0.5:
f[i] = 255
else:
f[i] = 192
open('b.bmp','wb').write(bytes(f))
import threading
import os
import urllib.request
def status(j,d):
if 'extended_entities' in d and 'media' in d['extended_entities']:
p = 'images/' + d['user']['screen_name']
if not os.path.exists(p):
os.makedirs(p)
for m in d['extended_entities']['media']: