Skip to content

Instantly share code, notes, and snippets.

@lon9
lon9 / file0.txt
Last active September 5, 2015 12:58
Webページのページングの時に必要になる超簡単なアルゴリズム ref: http://qiita.com/Rompei/items/cc4ca6cffa2fd3c3930a
p:ページナンバー
m:1ページに表示したい項目数
問:sql文を作成したい=>SQLのl:Limitとo:Offsetを求める。また、初期値としてそれぞれl=M,o=0とする。
アルゴリズム:
l=m
o=(p-1)*l
@lon9
lon9 / controllers.js
Last active September 4, 2015 11:26
Angucomplete-altの積みどころ ref: http://qiita.com/Rompei/items/9a69807f7d9fb98aaa8d
$scope.selectedFn = function($item){
$scope.hoges[this.$parent.$index].huga = $item.title;
}
$scope.changedInput = function(huga){
$scope.hoges[this.$parent.$index].huga = huga;
}
#!/bin/sh
#Move any where.
move(){
if [ ! "$#" -eq 1 ]; then
echo "The number of arameters must be 1."
return
fi
case $1 in
android) cd ~/android_workspace ;;
@lon9
lon9 / file0.xml
Last active November 2, 2017 01:35
Support design libraryのTabLayoutをタブレットで使用するときの注意点 ref: http://qiita.com/Rompei/items/34f039aca8262c7897b2
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
@lon9
lon9 / card_item.xml
Last active March 8, 2016 03:01
RecyclerView, GridLayoutManagerにCardViewを直接いれてはならない。 ref: http://qiita.com/Rompei/items/4794a122435ed82cf5d6
<Frame_Layout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<!--Some views -->
</CardView>
</FrameLayout>
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
@lon9
lon9 / getKey.java
Created May 20, 2015 14:16
Concealを使って文字列を暗号化してPreferenceに保存する。 ref: http://qiita.com/Rompei/items/c21c543707510720db2d
public static String getToken(Context context){
SharedPreferences preferences = context.getSharedPreferences(PreferenceValue.PREF_KEY, Context.MODE_PRIVATE);
String accessKey = preferences.getString(PreferenceValue.TOKEN_ACCESS_KEY, null);
String encryptedToken = preferences.getString(PreferenceValue.ENCRYPTED_KEY, null);
byte[] rawEncryptedToken = null;
String rawDecryptedToken = null;
if(encryptedToken!=null&&accessKey!=null) {
rawEncryptedToken = Base64.decode(encryptedToken, Base64.DEFAULT);
Crypto crypto = new Crypto(
@lon9
lon9 / file0.java
Created May 11, 2015 13:00
Statusbarのサイズ(高さ)を取得する。 ref: http://qiita.com/Rompei/items/4f83ab38f416b60897cb
/**
* Return Statusbar size.
* @param activity Activity
* @return Statusbar size
*/
public static int getStatusBarHeight(Activity activity){
final Rect rect = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rect);
return rect.top;
@lon9
lon9 / follow_test.py
Last active January 10, 2024 04:29
Function to increase follower on twitter
#キーワードで自動フォロー1000人
def autoFollow(api, query):
requestcount=1
global followCount
global wordCount
#リクエストが50回以下(検索人数1000人)で繰り返す
while requestcount<51:
print 'Do request %i' %requestcount
users = api.search_users(query, 20, requestcount)
requestcount+=1
@lon9
lon9 / CustomAdapter.java
Last active August 29, 2015 14:14
AndroidでYouTubeのサムネイルをアス比を直して表示する。 ref: http://qiita.com/Rompei/items/46ae14a49b7a383153db
public class CustomAdapter extends ArrayAdapter<VideoItems> {
private LayoutInflater layoutInflater;
private Context context;
public CustomAdapter(Context context, int textViewResourceId, List<VideoItems> objects, RequestQueue queue) {
super(context, textViewResourceId, objects);
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
}