Skip to content

Instantly share code, notes, and snippets.

def newSlider(state: PasswordGeneratorModel, labelres: Int, label: TextView, countRes: Int,
slider: SeekBar, enableTransform: (PasswordGeneratorModel, Boolean) => PasswordGeneratorModel,
isEnabled: PasswordGeneratorModel => Boolean, min: PasswordGeneratorModel => Int,
updateMin: (PasswordGeneratorModel,Int) => PasswordGeneratorModel,
seek1: SeekBarInfo, seek2: SeekBarInfo) = {
val ll = new LinearLayout(getActivity)
val cb = new CheckBox(...)
cb.setLayoutParams(stdH)
cb.setText(labelRes)
cb.setChecked(isEnabled(state)
IO(numSlider) >>= stdH >>= k.max(state.length) >>= k.progress(state.minNum) >>= k.enabled(state.num) >>=
hookM.seekBarChange.onProgressChanged((sb: SeekBar, p: Int, user: Boolean) => for {
st <- transformState(_.copy(minNum = p))
_ <- IO(minNumLabel) >>= k.text(getString(R.string.minimum_numbers, p.asInstanceOf[Integer]))
_ <- IO(uppSlider) >>= k.progress(math.min(st.minUpper, math.max(st.length - st.minNum - st.minSym, 0)))
_ <- IO(symSlider) >>= k.progress(math.min(st.minSym, math.max(st.length - st.minUpper - st.minNum, 0)))
} yield ()),
@pfn
pfn / layout.scala
Last active February 23, 2016 20:01
so dense
override def applyState[T](s: FragmentState[T]) = s match {
case OnCreateView(state, inflater, container) => s.applyResult(
l[ScrollView](l[LinearLayout](
IO(generatedPassword) >>= k.text(generate(state)) >>=
k.textAppearance(getActivity, android.R.style.TextAppearance_Medium) >>=
k.gravity(Gravity.CENTER) >>=
k.backgroundColor(getResources.getColor(android.R.color.darker_gray)) >>=
lpK(MATCH_PARENT, 48.dp)(margins(bottom = 16.dp)),
IO(lengthLabel) >>= k.text(getString(R.string.minimum_length, state.length.asInstanceOf[Integer])),
IO(lengthSlider) >>= stdH >>= k.progress(state.length - 8) >>=
@pfn
pfn / setwindowslongptr.py
Created February 19, 2016 19:53
hooking WndProc in hexchat
from ctypes import *
from ctypes.wintypes import *
import hexchat
import traceback
import sys
__module_name__ = "sethook"
__module_version__ = "1.0"
__module_description__ = "Demonstration of calling SetWindowsLongPtr from ctypes"
@pfn
pfn / passwords.scala
Last active February 19, 2016 07:14
colorizing passwords
sealed trait CharType
case object Uppercase extends CharType
case object Lowercase extends CharType
case object Symbol extends CharType
case object Digit extends CharType
case class Spans(chartype: CharType, start: Int, end: Int)
if (Option(strings.Get(PwDefs.PasswordField)) exists (_.Length > 0)) {
val passfield = new StandardFieldView(this)
passfield.first = first
first = false
@pfn
pfn / logcatactivity.scala
Created February 16, 2016 22:56
scalac fails too
package com.hanhuy.android.irc
import android.graphics.Typeface
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.{LinearLayoutManager, RecyclerView}
import android.view.ViewGroup
import android.widget.{TextView, LinearLayout}
import com.hanhuy.android.irc.model.{MessageAdapter, RingBuffer}
@pfn
pfn / android.scala
Last active February 17, 2016 04:44
pure activity start
package com.hanhuy.android.irc
import android.app.Activity
import android.os.Bundle
import android.view.{View, Menu}
import iota.IO
/** beware:
* https://youtrack.jetbrains.com/issue/SCL-9888
* https://issues.scala-lang.org/browse/SI-9658
@pfn
pfn / asm.scala
Created February 12, 2016 03:22
naive attempt at a state machine
import android.app.Activity
import android.os.Bundle
import ActivityStateMachine._
/**
* @author pfnguyen
*/
trait ActivityStateMachine[T <: State[T]] extends Activity {
@pfn
pfn / 00-example-usage.scala
Created January 27, 2016 05:36
startActivityForResult as Future
requestActivityResult(intent).onSuccessMain { case data =>
val ringtone = data.?.map(_.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI): Uri)
setRingtone(ringtone.fold("")(_.toString))
}
@pfn
pfn / log.txt
Last active January 21, 2016 23:12
package installation failure
[pfnguyen@GALACTICA output] $ ~/android-sdk-windows/build-tools/23.0.2/aapt.exe d xmltree keepshare-debug.apk AndroidManifest.xml | grep -A5 provider
E: provider (line=58)
A: android:label(0x01010001)=@0x7f070039
A: android:name(0x01010003)="com.hanhuy.android.keepshare.SearchProvider" (Raw: "com.hanhuy.android.keepshare.SearchProvider")
A: android:readPermission(0x01010007)="android.permission.GLOBAL_SEARCH" (Raw: "android.permission.GLOBAL_SEARCH")
A: android:exported(0x01010010)=(type 0x12)0xffffffff
A: android:authorities(0x01010018)=@0x7f070093
[pfnguyen@GALACTICA output] $ ~/android-sdk-windows/build-tools/23.0.2/aapt.exe d resources keepshare-debug.apk | grep 70093
spec resource 0x7f070093 com.hanhuy.android.keepshare:string/search_suggest_authority: flags=0x40000000
resource 0x7f070093 com.hanhuy.android.keepshare:string/search_suggest_authority: t=0x03 d=0x00000346 (s=0x0008 r=0x00) (PUBLIC)