Posts

encryption - Convert ecryption/decryption function from Python to PHP -

i have python script encrypt/decrypt urls: # -*- coding: utf-8 -*- import base64 operator import itemgetter class crypturl: def __init__(self): self.key = 'secret' def encode(self, str): enc = [] in range(len(str)): key_c = self.key[i % len(self.key)] enc_c = chr((ord(str[i]) + ord(key_c)) % 256) enc.append(enc_c) return base64.urlsafe_b64encode("".join(enc)) def decode(self, str): dec = [] str = base64.urlsafe_b64decode(str) in range(len(str)): key_c = self.key[i % len(self.key)] dec_c = chr((256 + ord(str[i]) - ord(key_c)) % 256) dec.append(dec_c) return "".join(dec) url = "http://google.com"; print crypturl().encode(url.decode('utf-8')) this works fine. example above url converted 29nx4p-joszs4czg2jpg4di= , decryption brings url. now want convert php function. far encryption w...

Android - Button text center gravity not working -

Image
i have xml layout in app (example of 1 button): <scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/scrollviewmain" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" > <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#fff0e8" > ///some views <button android:id="@+id/btnvysledkysportka" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbottom="@+id/chcksprotka" android:layout_alignright="@+id/chcksprotka" android:layout_aligntop="@+id/chcksprotka" android:layout_margin="3dp" android:la...

Import Excel data into an existing SQL Server 2005 table -

Image
i'm trying import data excel sheet existing sql server 2005 table. the table has following columns: name, surname, phonenumber ,bill and in same order in excel sheet. i've never attempted such thing before, after searching while told use: insert table select * openrowset('microsoft.jet.oledb.4.0', 'excel 8.0;database=c:\temp\test.xls', 'select * [sheet1$]') do need reference column names excel sheet sql server table columns? i'm not sql guru, consider myself beginner. can help? see here in management studio : choose db? choose source : and here following gui !!

rally - How do you tell you are running in debug mode in sdk2? -

how tell programatically in sdk2 if running in debug (local) mode (not installed in rally)? i looking in rally.app.context didn't see obvious there nothing in context purpose, far know, here trick can tell if running in rally, or outside: if (window.parent.rally.alm) { console.log('inside'); } else{ console.log('outside'); }

In pure javascript how do you transverse up a DOM element and target the parent? -

this question has answer here: javascript parent element , write holder div siblings 2 answers without using jquery , plain javascript. how 1 select parent of child element? example: <div> <p> <em class="stuff">abc</em> </p> </div> how select parent div container via class stuff ? its in pure javascript element.parentnode

Rails 4: form_for with nested resource and without -

in app, when regular user logs in, dropped in on dashboard displays service requests company belong_to . when admin logs in, dropped onto dashboard displays of company logos can login , file service requests. the views between regular user , admin user virtually exact same, outside of 1 or 2 entities on form (which controlled via cancan ). trying able use same form if admin creates sr or regular user creates sr. routes.rb: resources :service_requests resources :notes end namespace :admin '', to: 'dashboard#index', as: '/' resources :companies resources :service_requests, only: [:index, :new] end end if admin logs in , clicks on company logo , clicks create new sr, route /admin/companies/1/service_requests/new . if regular user logs in is, /service_requests/new . confused on how reuse same form both admin , non-admin side. because setting company_id on sr in create resource in servicerequestscontroller i fol...

C++ Find Certain Element in Queue -

the idea simple , task needs queue, please dont suggest other methods. i need have full queue, example 5 elements of (5,4,3,2,1) , user has enter position of element want moved front. e.g, position 3, element 2. new queue be: 2,5,4,3,1... i have been working on long time isnt hit wall ask help. nudge me working in right direction again :) thanks queue representations pretty arbitrary. i'd use deque: #include <deque> #include <algorithm> #include <iostream> int main() { std::deque<int> queue { 5, 4, 3, 2, 1 }; auto b = begin(queue); std::cout << "which element? "; int n; if (std::cin >> n && n > 0 && size_t(n) <= queue.size()) { std::rotate(b, b+n-1, b+n); (auto : queue) std::cout << << " "; } else { std::cout << "invalid input\n"; } } see live on coliru if queue mean lifo-access onl...