Skip to content

Instantly share code, notes, and snippets.

View hangingman's full-sized avatar
🦙

hangedman hangingman

🦙
  • Kanagawa, Japan
  • 21:33 (UTC +09:00)
View GitHub Profile
@seratch
seratch / repl.scala
Created August 9, 2013 08:27
mocked DBSession
scala> import org.mockito.Mockito._
import org.mockito.Mockito._
scala> implicit val session: DBSession = mock(classOf[DBSession])
session: scalikejdbc.DBSession = Mock for DBSession, hashCode: 339695449
scala> sql"select * from companies".map(_.toMap).list.apply()
res0: List[Map[String,Any]] = null
scala> :q
@panzi
panzi / portable_endian.h
Last active August 9, 2024 13:12
This provides the endian conversion functions form endian.h on Windows, Linux, *BSD, Mac OS X, and QNX. You still need to use -std=gnu99 instead of -std=c99 for gcc. The functions might actually be macros. Functions: htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh, htobe64, htole64, be64toh, le64toh. License: I hereby put …
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
@davidbella
davidbella / person.rb
Created October 10, 2013 13:37
Ruby: Dynamic meta-programming to create attr_accessor like methods on the fly
class Person
def initialize(attributes)
attributes.each do |attribute_name, attribute_value|
##### Method one #####
# Works just great, but uses something scary like eval
# self.class.class_eval {attr_accessor attribute_name}
# self.instance_variable_set("@#{attribute_name}", attribute_value)
##### Method two #####
# Manually creates methods for both getter and setter and then
@uchan-nos
uchan-nos / bootpack.ld
Created January 2, 2014 08:21
GNU LD linker script for BitNOS (HariboteOS-like operating system)
OUTPUT_FORMAT("binary")
ENTRY(KernelMain)
HEAP_SIZE = 0;
MMAREA_SIZE = 0;
__ctors = ADDR(.ctors);
__ctors_count = SIZEOF(.ctors) / 4;
SECTIONS
@athos
athos / core.clj
Last active January 26, 2017 00:43
「数字6桁パスワードのハッシュ値の総当たり、PHPなら約0.25秒で終わるよ(http://z.tokumaru.org/2014/02/6php025.html )」で、PHPに比べてClojureがやたら遅いという話だったので、Clojureのコードをいろいろいじってみた。
(ns six-length.core
(:require [clojure.core.reducers :as r]
[clojure.string :as s])
(:import [java.security MessageDigest]
[javax.xml.bind DatatypeConverter]))
(set! *warn-on-reflection* true)
(def hexdigest
(let [digester (MessageDigest/getInstance "MD5")]
@ponkotuy
ponkotuy / md5.scala
Created February 11, 2014 08:24
6桁数字をMD5で総当たりしてみた
import java.security.MessageDigest
val md5 = MessageDigest.getInstance("MD5")
def equals[T](xs: Array[T], ys: Array[T]): Boolean = {
if(xs.size != ys.size) return false
var i = 0
while(i != xs.size) {
if(xs(i) != ys(i)) return false
@mala
mala / gist:9086206
Created February 19, 2014 04:49
CSRF対策用トークンの値にセッションIDそのものを使ってもいい時代なんて、そもそも無かった

概要

http://co3k.org/blog/csrf-token-should-not-be-session-id について。

この記事では触れられていませんが、

  • むかし、セッションIDをHTMLソース中に埋め込んでも脅威は変わらないと主張した人がいました
  • 正確には「hiddenの値のみ漏れやすいような特殊な脆弱性が無ければ」という前提であったけれど、実際にそのようなバグはあったし、予見されていた。
  • とても影響のある人だったので、色々なサイトや書籍がその方法を紹介し、安全なウェブサイトの作り方にも載ってしまいました

この際ハッキリ言っておくべきだと思うので書きますが、そもそもセッションIDを(HTMLソース中に埋め込む)CSRF対策トークンとして使うのは間違いでした。最初から間違っていたのです。正確に言うとCSRFの話は関係ないですね。CSRF関係なく、特に「単体で」セッションハイジャックが可能になるような値を、HTMLソース中に埋め込むべきではありません。

@lfender6445
lfender6445 / gist:9919357
Last active May 13, 2025 16:00
Pry Cheat Sheet

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

@gakuzzzz
gakuzzzz / 1_.md
Last active March 7, 2025 06:35
Scala の省略ルール早覚え

Scala の省略ルール早覚え

このルールさえ押さえておけば、読んでいるコードが省略記法を使っていてもほぼ読めるようになります。

メソッド定義

def concatAsString(a: Int, b: Int): String = {
  val a_ = a.toString();
  val b_ = b.toString();
@borella
borella / gist:11285316
Created April 25, 2014 10:48
Google Chrome with local file access on Mac OS X
open /Applications/Google\ Chrome.app --args --allow-file-access-from-files