Skip to content

Instantly share code, notes, and snippets.

@ilguzin
ilguzin / regexp_unpackaging.scala
Created April 8, 2013 18:48
regular expression vs patterns matching in Scala
scala> val s = "Me Moscow 2012"
s: String = some text 2012
scala> val PersonLocation = """(.+) (.+) (.+)""".r
PersonLocation: scala.util.matching.Regex = (.+) (.+) (.+)
scala> val PersonLocation(person, city, year) = s
person: String = Me
city: String = Moscow
year: String = 2012
@ilguzin
ilguzin / pass_java_list_to_scala.scala
Created April 4, 2013 13:53
Calling Scala code from Java with java.util.List when Scala's List is expected
// Implicit
import scala.collection.JavaConverters._
// For method:
def doSomething(things: List[Thing]): List[Result] = { ... }
// add the same method with another signature:
def doSomething(things: java.util.List[Thing]): java.util.List[Result] =
doSomething(things.asScala.toList).asJava
@ilguzin
ilguzin / set_height_to_ListView_wrapped_by_ScrollView.java
Last active December 12, 2015 04:28
The snippet gives you an ability to set ListView height according to elements number in it, when the ListView is placed inside ScrollView. Stolen from SO.
class HackUtils {
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
@ilguzin
ilguzin / app.js
Last active December 9, 2015 07:11
Embedding ui-select into ui-grid cell
app.run(['$templateCache', function ($templateCache) {
/**
* Cached Angular Template for ui-grid/uiSelect.
* Allows to use in ui-grid as 'editableCellTemplate' field definition
*/
$templateCache.put('ui-grid/uiSelect',
'<ui-select-grid-cell-wrap>' +
'<ui-select ng-model="MODEL_COL_FIELD" theme="selectize" ng-disabled="disabled" append-to-body="true">' +
'<ui-select-match placeholder="Choose...">{{ $select.selected[editDropdownValueLabel] }}</ui-select-match>' +
@ilguzin
ilguzin / MyMapActivity.java
Created November 29, 2012 13:28
Simple way of making long tap event work in MapView. MapActivity class
public class MyMapActivity extends MapActivity
implements OnGestureListener {
...
private GestureDetector gestureDetector;
@Override
@ilguzin
ilguzin / ShowMapActivity.java
Created November 29, 2012 13:30
Simple way of making long tap event work in MapView. ShowMapActivity class
public class ShowMapActivity extends MapActivity {
...
private long touchActionDownStartTime;
private float histX;
@ilguzin
ilguzin / dashboardCtrl.coffee
Last active August 29, 2015 14:24
example code
class dashboardCtrl
NOTIFICATIONS_STATUS_UPDATE_PERIOD = 30 # Seconds
@$inject = ['$scope', '$q', '$log', '$cookies', '$state', '$rootScope', '$timeout', 'MonitoringService',
'loginService', 'SettingsService']
_s = {}
scheduleAgentDataUpdate = () ->
@ilguzin
ilguzin / gist:ff58a8376228234e1e5b
Last active August 29, 2015 14:21
WordPress's workaround for is_ssl() function when proxying from https to http. HTTP_X_FORWARDED_PROTO feature. Stolen from https://wordpress.org/support/topic/request-modify-is_ssl-function-to-check-for-http_x_forwarded_proto
/**
* Determine if SSL is used.
*
* @since 2.6.0
*
* @return bool True if SSL, false if not used.
*/
function is_ssl() {
if ( isset($_SERVER['HTTPS']) ) {
if ( 'on' == strtolower($_SERVER['HTTPS']) )
@ilguzin
ilguzin / content.html
Last active August 29, 2015 14:08
Average color of the picture. Stolen from http://jsfiddle.net/xLF38/ . Get data uri from image http://dataurl.net/#dataurlmaker
Setting the BODY's background to the average color in the following image:
<br/><br/>
<img id="i" src="data:image/jpeg;base64,/9j/7gAOQWRvYmUAZAAAAA........Q==" />
@ilguzin
ilguzin / color2text_brightness.coffee
Last active August 29, 2015 14:08
Derive text color depending on background brightness
#Color text change
rgb = [
"255"
"0"
"0"
]
setInterval (->
c = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"
#http://www.w3.org/TR/AERT#color-contrast