Skip to content

Instantly share code, notes, and snippets.

Avatar
🏯
Working from castle

itmammoth itmammoth

🏯
Working from castle
View GitHub Profile
@itmammoth
itmammoth / jquery.autoAdjust.js
Last active May 26, 2019
jQuery plugin that provides auto-extension (currently `width` is only supported) to elements
View jquery.autoAdjust.js
/**
* ex)
* <input type="text" class="jq-auto-adjust" data-base-width="60" data-base-window-width="1280">
* $('.jq-auto-adjust').autoAdjust();
*/
(function($) {
'use strict';
var methods = {
init: function(options) {
@itmammoth
itmammoth / safe.kt
Created May 25, 2019
[Kotlin] Unwrap null objects or return immediately
View safe.kt
fun <T1, T2> safe(t1: T1?, t2: T2?): Pair<T1, T2>? {
return if (t1 == null || t2 == null) null else Pair(t1, t2)
}
fun <T1, T2, T3> safe(t1: T1?, t2: T2?, t3: T3): Triple<T1, T2, T3>? {
return if (t1 == null || t2 == null || t3 == null) null else Triple(t1, t2, t3)
}
// Usage (case in fragments)
val (context, activity) = safe(context, activity) ?: return
@itmammoth
itmammoth / file0.txt
Created Aug 12, 2018
スクロールしない高さ自動調整のListView ref: https://qiita.com/itmammoth/items/ba84711e646f625c98e0
View file0.txt
class NonScrollListView : ListView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
init {
isVerticalScrollBarEnabled = false
isHorizontalScrollBarEnabled = false
}
@itmammoth
itmammoth / file0.txt
Last active Jul 27, 2018
kotlinでif文の条件に代入式を使いたい ref: https://qiita.com/itmammoth/items/e21dba17373e0aa7353e
View file0.txt
if (val date = arguments?.getSerializable(ARG_DATE) as LocalDate) {
...
@itmammoth
itmammoth / backboneSortable.js
Last active May 17, 2018
A jQuery plugin over jQueryUI sortable that arranges Backbone.Collection and item views as the html list are
View backboneSortable.js
/**
* $.backboneSortable
*/
(function(){
var methods = {
init: function(options) {
var settings = $.extend({
// defaults
}, options);
View deepPluck.js
/**
* Usage:
* var models = [{ attributes: { name: 'Scott' } }, { attributes: { name: 'Tiger' } }];
* deepPluck(models, 'attributes', 'name'); //=> ['Scott', 'Tiger']
*/
var deepPluck = function(array) {
var copiedArray = [].concat(array);
for (var i = 1; i < arguments.length; i++) {
copiedArray = _.pluck(copiedArray, arguments[i]);
}
@itmammoth
itmammoth / file0.sql
Last active Apr 5, 2018
【MySQL】トランザクションを要するストアドプロシージャのテンプレート ref: https://qiita.com/itmammoth/items/54309d4cb4150f45f1d6
View file0.sql
DELIMITER //
CREATE PROCEDURE プロシージャ名()
BEGIN
-- DECLARE 変数
-- DECLARE CURSOR
DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING
BEGIN
GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE, @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
@itmammoth
itmammoth / start_emulator.sh
Last active Sep 21, 2020
Start an android emulator with changing DNS server to Google public DNS
View start_emulator.sh
#!/bin/bash
EMULATOR=~/Library/Android/sdk/tools/emulator
if [ $# -ne 1 ]; then
echo "ERROR: Please specify the target AVD from the list below" 1>&2
$EMULATOR -list-avds 1>&2
exit 1
fi
$EMULATOR -avd $1 -dns-server "8.8.8.8,8.8.4.4"
@itmammoth
itmammoth / on_page_load.coffee
Last active Oct 13, 2017
A javascript function that allows you to do something on a particular page in rails application
View on_page_load.coffee
#
# Call the given callback function when the indicated page is loaded
#
# [Get ready]
#
# 1. Add data attributes to the body tag in your application layout file.
# ex)
# <body data-controller="<%= controller_name %>" data-action="<%= action_name %>">
#
# 2. Put this file into app/assets/javascripts/