Skip to content

Instantly share code, notes, and snippets.

View arpit's full-sized avatar

Arpit Mathur arpit

View GitHub Profile
@arpit
arpit / Carat.js
Created March 4, 2012 17:01
Setting the carat in a contentEditable div
function setCaratTo(contentEditableElement, position)
{
var range,selection;
if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
{
range = document.createRange();
range.selectNodeContents(contentEditableElement);
//range.collapse(true);
@arpit
arpit / layout_transition_stagger.java
Created July 13, 2012 22:27
Stagger LayoutTransitions in Android
package com.arpit.animatortest;
import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
@arpit
arpit / gistio.md
Created July 18, 2012 23:24
GistIO test

Testing a Gist

I think it could be cool. For a number of reasons:

  • Like one
  • and 2
@arpit
arpit / gist:5165994
Created March 14, 2013 22:59
wtf mysql
Mar 13 15:20:29 ip-10-212-127-222 kernel: [1388067.480652] [ 3971] 106 3971 221943 14598 0 0 0 mysqld
Mar 13 15:20:29 ip-10-212-127-222 kernel: [1388067.480742] Out of memory: Kill process 3971 (mysqld) score 97 or sacrifice child
Mar 13 15:20:29 ip-10-212-127-222 kernel: [1388067.480973] Killed process 3971 (mysqld) total-vm:887772kB, anon-rss:58392kB, file-rss:0kB
Mar 13 15:20:29 ip-10-212-127-222 kernel: [1388067.620972] init: mysql main process (3971) killed by KILL signal
Mar 13 15:20:29 ip-10-212-127-222 kernel: [1388067.621019] init: mysql main process ended, respawning
Mar 13 15:20:29 ip-10-212-127-222 kernel: [1388068.095579] type=1400 audit(1363188029.689:15): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=3728 comm="apparmor_parser"
Mar 13 15:20:30 ip-10-212-127-222 kernel: [1388068.658259] init: mysql main process (3732) terminated with status 1
Mar 13 15:20:30 ip-10-212-127-222 kernel: [1388068.658325] init: mysql main process ended, respawni
* Android added a method in the compatability lib called postOnAnimation that executes a Runnable in sync with display VSync. Does this help animation?
* You can add views during the layout pass by calling addViewInLayout
* Swapping a view's layer type (between hardware and software) may improve animation performance.
@arpit
arpit / find-replace
Created November 28, 2014 20:06
Find pattern to read all public vars in a swift model and replace in your json parser
//Find:
var\s([A-Za-z_]+):\s?[A-Za-z!_\\?]+
//Replace:
if(g[i]["$1"] != nil && g[i]["$1"] as? NSNull == nil){
goal.$1 = g[i]["$1"] as AnyObject? as String!
}

Figured out my layout issue: I had set the frame on a UIView and added it to a parent view. Under the hood, iOS translated the frame rectangle to constraints (cause I hadn't set "setTranslatesAutoresizingMaskToConstraints" to false). So when the parent view was resized later, the child view stretched along with it. Unlike the default behavior views with frames set that just stay that size regardless.

@arpit
arpit / arraydo.rb
Created July 14, 2016 00:50
Array basics
# arr.each_with_index do |value, index|
# arr[index] = value * 2
# end
(0..arr.length - 1).each do |v|
arr[v] = arr[v] * 2
end
#create empty hash
myhash = {}
# or
myh = Hash.new
# keys no value
info = { :name => nil, :address => nil }
#set value of keu
info[:name] = "arpit"
@arpit
arpit / user_oop.rb
Created July 24, 2016 23:51
Ruby OOP / Classes practice
class User
attr_accessor :first_name, :last_name
def self.set_species (s)
@@species = s
end